passing arraylist via web services

inzo21

Regular
Joined
Nov 5, 2003
Messages
74
Hello all,

new problem of the day. I want to pass a list of string names in from a web service to a client. I have tried using both an array of strings, an arraylist, and a collection - all to no success. My preference is to use an arraylist for the iteration and array manipulation methods already built in. Here is the error I get:

Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Collections.ArrayList may not be used in this context.


On the service, I use the following code for testing.


Public Function GetManifest()
Dim tar As New ArrayList
m_mancounter = 0
tar.Add("test")
tar.Add("test2")
Return tar
End Function


the client code reads:


Public Sub GetAllFiles()
'Try
Console.WriteLine("processing manifest")
Dim availablefiles As Object
Dim proxy As myservice.servmethods = New myservice.servmethods
availablefiles = proxy.GetManifest
Console.WriteLine("filecount: " & availablefiles.Count.ToString)
If Not (availablefiles.Count = 0) Then
For Each i As String In availablefiles
Console.WriteLine("file: " & i)
Next
Else : Console.WriteLine("Array is Empty!")
End If

'Catch ex As Exception

'End Try

End Sub

I declare an object rather than an arraylist based on an article I read here from VBAhole... I think ;-)

Does anyone have any clue what I'm doing wrong or have any ideas on how I can send this info over without high bandwidth - i.e. no xml docs or class bojects?

thanx in advance

inzo
 
Are you using Visual Studio?
Here is what I do to get the web service up and running. Start by passing a string to make sure you have the process working before you move on to the arraylist.

Add the web reference in the solution explorer, I usually change the name at this point to something more meaningful.

Then instantiate an instance of the web service proxy:
Dim obj As New aWebServiceClass.aWebServiceName

Then call the web method on the obj.

If your setup is correct when you type the following:
dim returnstr as String
returnstr = obj.MethodName(str)

IntellinonSense should pickup your web methods after you hit the period.

If you can get this far then go for the arraylist.
One of your issues may be

Public Function GetManifest()

If you got away with writing this you probably have Option Strict Off which is a bad thing. Turn it on. You'll get an error saying you can't have a function without a return value. You want:
Public Function GetManifest(strParam) as ArrayList

I think the previous post you are refering to was when I couldn't get anything out of the return value although I don't recall so well. You may need to pass an object and then ctype back to the array. I forgets.
 
No soup!

Hey VB...

I tried your suggestions and I guess it seems to be a problem with the serialization. I placed option strict on, and attempted passing a string from the web service.

In the client, I create a string object and make it equal the proxy.getstring() function from the web service. It compiles, but at runtime I get the following error:

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from type 'XmlNode()' to type 'String' is not valid.


I am able to call other functions and subroutines from the web service - but they are returned as byte arrays. At this point, I'm still not sure what I'm doing wrong. Do you think I need to serialize the string into xmla nd then deserialize it on the client end?

thanks again for the help. I really need it as I learn this stuff.

inzo
 
Really weird

Okay - on a whim, I tried adding a parameter to to the method so that in the web service it reads:

public function getstring(s as string) as string
s = s & "-test"
return s
end function

I then call the proxy to this as dim proxy as myservice.myclass = new myservice.myclass

proxy.getstring("client call")

and it works. The only change was adding a parameter to the method call. Now I'm completely confused. Does anyone have any idea what is going on in the backend?

inzo
 
Back
Top