VBAHole22 Posted October 22, 2003 Posted October 22, 2003 I have a web service that has a webmethod that is supposed to return an ArrayList. The problem is when I build my client application in the object browser the method appears to return an object and not an arraylist. When I try to to say: Dim GetArrayList As ArrayList GetArrayList = (MyService.ArrayListType) I get an underline and the error is something like 1-dimensional array of system.object cannot be converted to arraylist. Is there something I am missing? Can I convert the object to an Arraylist before the webmethod returns it? <WebMethod(Description:="Return an array of integers")> Public Function ArrayListType() As ArrayList End Function Quote Wanna-Be C# Superstar
*Experts* Nerseus Posted October 22, 2003 *Experts* Posted October 22, 2003 Can you have your webmethod return something else, like a Hashtable (which is serializable) or a DataSet? Offhand, I don't think you can get the original data from the arraylist over a webservice. It's best to use objects that can be serialized (meaning converted to a format that can go over a stream, like the web). -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
VBAHole22 Posted October 22, 2003 Author Posted October 22, 2003 I see what you are saying there. All I am passing is text. How would I go about using the Dataset? I am a little worried about for the following reason. The thing that generates the text values is another program that I have set a reference to. Its a GIS program called ArcMap. It also has a dataset object and I don't know how to use the one without confounding the other. I do appreciate your help greatly. Seems like dot.net is like the wild west that the internet was at one time. It's every man for himself and there are no rules or regulations (at least that are written down anywhere). Quote Wanna-Be C# Superstar
*Gurus* Derek Stone Posted October 22, 2003 *Gurus* Posted October 22, 2003 The ArrayList is serializable. It's one of the more commonly used data types in Web Services. Quote Posting Guidelines
*Experts* Nerseus Posted October 22, 2003 *Experts* Posted October 22, 2003 Whoops - I had no idea. Any ideas on how to help out, Derek? Do you just have to change the proxy into ArrayList from object, or do something else? -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
VBAHole22 Posted October 22, 2003 Author Posted October 22, 2003 Must be doing something else wrong: Here is my service webmethod #Region " strArrayList " <WebMethod(Description:="Return an array of strings")> Public Function strArrayList() As ArrayList Dim strings As New ArrayList(4) strings.Add("dopey") strings.Add("grumpy") strings.Add("sleepy") strings.Add("jokey") strings.Add("dumpy") Return strings End Function #End Region And here is my client calling code on another machine: Private Sub TestService() Dim MyService As New WebService.Service1 Dim GetArrayList As ArrayList() Dim k As String GetArrayList = (MyService.strArrayList) For i = 0 To UBound(GetArrayList) - 1 ListBox3.Items.Add(GetArrayList(i)) Next end Sub I got the underline to go away by adding the () after the dim GetArrayList but now it breaks during runtime and strArrayList is still an object and not an ArrayList. Quote Wanna-Be C# Superstar
VBAHole22 Posted October 22, 2003 Author Posted October 22, 2003 It's working all of the sudden and the only line I changed was in the webmethod as follows: Dim strings As New ArrayList In the example on MSDN they have ArrayList() but it won't even let me write that. The () disappears after i type it. Oh well. Quote Wanna-Be C# Superstar
VBAHole22 Posted October 22, 2003 Author Posted October 22, 2003 Almost forgot there was one other important mod that I made. In the client calling code I changed: Dim GetArrayList As ArrayList() to Dim GetArrayList As Object So now it is reading in as an object but I can still parse it out to a listbox as if it were a arraylist. Quote Wanna-Be C# Superstar
VBAHole22 Posted October 22, 2003 Author Posted October 22, 2003 Of course I am never satisfied with what I have. The issue now is this: I cannot manipulate the arraylist in my client code like I can in my web service code. For instance if I want to sort the list I have to do it in the webservice because in the client code the Object doesn't expose this method. Now an easy way around this would be to include a boolean parameter for sorted or unsorted and figure it out in the service. True. But what about the count of elements in the arralylist? I can't pass this back to the calling code can I? I was under the impression that the webmethod (like a regular function) was restricted to passing back a single value. I guess I could stack the count on the end of the arraylist but that seems to be a hack to me. How can I get around this problem? Quote Wanna-Be C# Superstar
bungpeng Posted September 21, 2004 Posted September 21, 2004 I faced the same problem, can't return "ArrayList" from web service... any solution? Quote
Administrators PlausiblyDamp Posted September 21, 2004 Administrators Posted September 21, 2004 try Dim GetArrayList As ArrayList and see if that works your original code Dim GetArrayList As ArrayList() declared an array of ArrayLists. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bungpeng Posted September 22, 2004 Posted September 22, 2004 Don't understand, I define in Webmethod in XML Web service which return "ArrayList", but when I call from ASP.NET, this function return "Object", not "ArrayList"... Is there anyway I can retrieve as ArrayList rather than Object? Quote
Administrators PlausiblyDamp Posted September 22, 2004 Administrators Posted September 22, 2004 Could you post the code for the web method in question? Also have you tried refreshing the web reference in the client - just to make sure it was using the most current version of the WSDL. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
pinster Posted September 23, 2004 Posted September 23, 2004 What about casting your object to an arraylist? CType(Object,ArrayList) Quote Nothing is impossible in Programming! So, take it easy and let us all share your problem. :)
bungpeng Posted September 23, 2004 Posted September 23, 2004 What about casting your object to an arraylist? CType(Object,ArrayList) Try before, not working? Unable to convert to ArrayList, I think because the Object here is normal array, not ArrayList object, so can't convert Quote
Joe Mamma Posted September 24, 2004 Posted September 24, 2004 Arraylist does not derive from MarshalByValueComponent (which I am assuming you want the entire array. does your array list contain simple value types??? try deriving a class from ArrayList applying the [serializable] attribute to it. If that doesn't work you might want to implement the ISerializable interface on your array list derivative. A simple implementation will lock your arraylist to specific types. there are techniques for deriving a universal object serializer but it is beyond the scope of this post. I recommend 'Advanced .NET Remoting' Rammer [apress] I am waiting for the second edition that is supposed to be out any day now. I have MSPress' .Net Remoting, hich sucks in my opinion. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.