ArrayList as webservice parameter

Last post 01-29-2008 9:47 AM by larrydotnet. 5 replies.

Sort Posts:

  • ArrayList as webservice parameter

    01-25-2008, 2:01 PM
    • Member
      273 point Member
    • larrydotnet
    • Member since 12-09-2002, 8:43 AM
    • Ecuador
    • Posts 110

    Hello,

    I was trying to get an arraylist as a parameter in a webservice but when i get the instance of the proxy class on the client it's shown as an Object array.  My arraylist is as simple as a group of strings, no object based arraylist is needed.

    <WebMethod> Function MyMethod(data as ArrayList) as boolean

    End Function

    and on the client the signature is :

    MyMethod (returnvalue() as Object)

    That means, i have to make a explicit cast to get at least an Array object and not an arraylist as original.

    Could you tell me how to pass the arraylist to the webmethod and get the same type of object as a returned data on the client?

    I appreciate your support.

    Thanks.

    Larry. 

     

    Larry Suárez.
  • Re: ArrayList as webservice parameter

    01-25-2008, 3:00 PM
    • All-Star
      20,998 point All-Star
    • Jeev
    • Member since 11-24-2005, 12:49 PM
    • Posts 3,163
    Jeev
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If you get the answer to your question, please mark it as the answer.
  • Re: ArrayList as webservice parameter

    01-25-2008, 5:08 PM
    • Member
      273 point Member
    • larrydotnet
    • Member since 12-09-2002, 8:43 AM
    • Ecuador
    • Posts 110

    Thanks for your suggestion.

    I was reading that article and as the comments below say, it needs to show the call to the web method on the client, condiering it could be an issue with the arraylist parameter.  It seems to be an array of objects instead of an ArrayList.  The only way i can get around is by defining a native array of strings as parameter and work with a List (of String) inside my webmehtod, i used the .ToArray method to get the final parameter value.

    On my webmethod (MessageCollection is System.Collections.Generic.List(Of String)  and Mensajes is the returned parameter - Array of string ):

    If Me._MessageCollection IsNot Nothing Then
        mensajes = Me._MessageCollection.ToArray
    Else
        mensajes = Nothing
    End If

     

    Do you know another way to simply return an ArrayList as parameter and get the same type on the client (webservice consumer)?

    I appreciate your support.

    Larry.

    Larry Suárez.
  • Re: ArrayList as webservice parameter

    01-29-2008, 3:16 AM
    Answer

    Hi Larry,

    That because we don't know whether client side use  .net framework , which include arraylist class,  client proxy always use object[] instead of using arraylist, You must do some type conversion to make parameter compatible . If you only use string array, you can use your approach to implement it. If arraylist include some ojects, you should do like below:

    object[] al = new object[3];

    al[0] = "1";

    al[1] = "2";al[2] = "3";

     

    object[] myArray= myService.GetArrayList(al);

    MessageBox.Show("OK");

    Best regards,
    Guang-Ming Bian - MSFT

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: ArrayList as webservice parameter

    01-29-2008, 3:47 AM
    • Member
      116 point Member
    • easydeepan
    • Member since 01-19-2008, 8:57 AM
    • Posts 33

    Convert it into bytes and send.

    During reterival getbytes and using ctype convert it to the orginal format.

    Try it will work!

  • Re: ArrayList as webservice parameter

    01-29-2008, 9:47 AM
    • Member
      273 point Member
    • larrydotnet
    • Member since 12-09-2002, 8:43 AM
    • Ecuador
    • Posts 110

    Yes, actually object array is the best solution for this scenario and now i am clear about webservice limits :)

    Thanks a lot for your comments.

    Larry.

    Larry Suárez.
Page 1 of 1 (6 items)