Passing collection to web service in .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wish to pass a collection object to a web service method in VB.NET, but when i try to do so i get an error message that "There was an error generating the XML", i even tried the XMLSerializer, but the same error came at different point in the program.
Can anyone tell me how to pass a collection to a web service.

User submitted from AEWNET (http://www.aewnet.com/)
 
Guest,

I made this sample some days ago on a question in this newsgroup, I dont
know if it is the best method, it is about an arraylist.


\\\Create a webservice project, paste this.
<System.Web.Services.WebService(Namespace:="http://tempuri.org/WebServiceNew/NewService")>
_
Public Class NewService
Inherits System.Web.Services.WebService
#Region " Web Services Designer Generated Code "
-----------------------------------------------------------
<WebMethod()> _
Public Function GiveArray() As String
Dim Myarray As New ArrayList
Dim myrecord As New Myfields
myrecord.fielda = "Hello"
myrecord.fieldb = "World"
Myarray.Add(myrecord)
Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim mem As New IO.MemoryStream
bf.Serialize(mem, Myarray)
Return Convert.ToBase64String(mem.ToArray())
End Function
<Serializable()> Public Class Myfields
Public fielda As String
Public fieldb As String
End Class
End Class
///
\\\Create (Add) a new winform project
'Set in that a reference to the project above
'Add a listbox
'Paste this code in
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
Dim myservice As New localhost.NewService
Dim bf As New
Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim a As String = myservice.GiveArray
Dim mem As New
IO.MemoryStream(Convert.FromBase64String(myservice.GiveArray))
Dim myarraylist As ArrayList = _
DirectCast(bf.Deserialize(mem), ArrayList)
ListBox1.Items.Add(DirectCast(myarraylist(0), _
WebServiceNew.NewService.Myfields).fielda)
ListBox1.Items.Add(DirectCast(myarraylist(0), _
WebServiceNew.NewService.Myfields).fieldb)
End Sub
///

I hope this helps a little bit?

Cor

"Guest" <Guest@aew_nospam.com>

....
 
Back
Top