WebService & Classes

JRock

Membro
Olá pessoal, parabéns pelo forum bestial, pela primeira vez decime registar e começar com uma duvida ^^

[VB.NET2005)

Precisava da vossa ajuda para resolver este quebra-cabeças
tongue.gif
Em termos prácticos é o seguinte :

-WebService gera :

- <ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.creationslabs.pt/webservices">
<anyType xsi:type="xsd:string">00001</anyType>
<anyType xsi:type="xsd:string">5606584000013</anyType>
<anyType xsi:type="xsd:string">RELOGIO LV277ME</anyType>
<anyType xsi:type="xsd:string">00010</anyType>
<anyType xsi:type="xsd:string">5606584000105</anyType>
<anyType xsi:type="xsd:string">RELOGIO F1143/BE</anyType>
</ArrayOfAnyType>

-Mas gostaria de :

- <ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.creationslabs.pt/webservices">
+<Artigo>
<cod>00001</cod>
<barras>5606584000013</barras>
<desc>RELOGIO LV277ME</desc>
-</Artigo>
+<Artigo>
<cod>00001</cod>
<barras>5606584000013</barras>
<desc>RELOGIO LV277ME</desc>
-</Artigo>
etc...
</ArrayOfAnyType>

Eu suponho que seja com uma classe, mas não tou a conseguir , dá-me sempre algum tipo de erro
sad.gif


Muito Obrigado pela Ajuda!!!
 
Qual é a assinatura do método do WebService?

Normalmente, se definires como:

public Artigo[] Metodo(...)

e definires a classe Artigo como pública, o WSDL já é o que pretendes...
 
Hey tkz pela ajuda,

Eu estou a gerar a resposta através deste code :

<WebMethod()> _
Public Function gceArtigos(ByVal strServerVirg ... ) As ArrayList

'BASICO
Dim MyResults As DataSet
MyResults = ...'Resultado de uma funcao não importante , busca aos dados ao SQL, como DataSet


'ARRAY PARA O FLEX
Dim MyArrayList As ArrayList = New ArrayList

For intCounter As Integer = 0 To MyResults.Tables(0).Rows.Count - 1
MyArrayList.Add(MyResults.Tables(0).Rows(intCounter).Item(0))'coluna cod artigo
MyArrayList.Add(MyResults.Tables(0).Rows(intCounter).Item(1))'coluna cod barras
MyArrayList.Add(MyResults.Tables(0).Rows(intCounter).Item(2))'coluna desc
Next

Return MyArrayList


Agora não sei como se encaixa o que me disseste nisto, será que me poderiam ajudar dando um exemplo ? tkz

Bem assinatura penso que perguntas por isto :

<s:element name="myArtigosResponse">
<s:complexType>
<s:sequence>

<s:element minOccurs="0" maxOccurs="1" name="myArtigosResult" type="tns:ArrayOfAnyType" />
</s:sequence>
</s:complexType>
</s:element>
 
Última edição:
Em vez de retornares uma ArrayList, tens de fazer uma lista de Objectos do tipo Artigo.

Ou devolver uma Lista genérica de artigos... mas nao sei como se faz em VB... só C# ( List<Artigo> )

Tens de declarar a Classe Artigo com os campos que queres.
 
TÁ QUASEE :D

Pois também acho que seja uma lista de objectos, mas não tou a conseguir faze-la..

Eu em C# consegui... em VB.net é que não.. Ei-la:

<WebMethod()> _
Public Function gceArtigos(ByVal strSer... As String) As Artigos

'BASICO
Dim MyResults As DataSet
MyResults = .....


Dim MyList As Artigos = New Artigos

For intCounter As Integer = 0 To MyResults.Tables(0).Rows.Count - 1
MyList.cod = MyResults.Tables(0).Rows(intCounter).Item(0)
MyList.barras = MyResults.Tables(0).Rows(intCounter).Item(1)
MyList.desc = MyResults.Tables(0).Rows(intCounter).Item(2)
Next

Return MyList

End Function

Public Class Artigos
Public cod As String
Public barras As String
Public desc As String
End Class



Só estou a obter os últimos 3 objectos , possivelmente porque estou a substituir no loop, alguém tem ideias para adicionar em vez de substituir ?

Tambem tentei .... += ... nada

De duvida de caracacá :P

Tkz
 
Última edição:
Código:
 <WebMethod()> _
Public Function gceArtigos(ByVal strSer... As String) As List(Of Artigo)

'BASICO
Dim MyResults As DataSet
MyResults = .....


Dim MyList As List(Of Artigo) = New List(Of Artigo)

For intCounter As Integer = 0 To MyResults.Tables(0).Rows.Count - 1

Dim art as Artigo = New Artigo

art.cod = MyResults.Tables(0).Rows(intCounter).Item(0)
art.barras = MyResults.Tables(0).Rows(intCounter).Item(1)
art.desc = MyResults.Tables(0).Rows(intCounter).Item(2)

MyList.Add(art)


Next


Return MyList

End Function



 Public Class Artigos
Public cod As String
Public barras As String
Public desc As String
End Class

É +- isto.
 
Back
Topo