Passing ArrayList to web service

Last post 07-04-2009 12:00 AM by johnwsaunders3. 6 replies.

Sort Posts:

  • Passing ArrayList to web service

    11-05-2008, 1:39 AM
    • Member
      2 point Member
    • feddo04
    • Member since 11-05-2008, 5:42 AM
    • Posts 2

    Hi all...

    I'm using ASP.NET web service and windows application.

    All I want is how to passing ArrayList to web service?

    when I calling web method and passing string or int, it works fine. but when I passing ArrayList, it doesn't work and I don't know what is the problem.

    for example in windows application :

     myMethod.addNew(stringValue, intValue, listValue) // where listValue is ArrayList...

    it give me error with listValue... but if I called another function in the same windows application and passing ArrayList, it works fine.

    the problem only when I passing ArrayList to web service...

    How can I passing ArrayList to web service? pls I need help...

    thanks for reading my quistion and I respect for any reply...

     

  • Re: Passing ArrayList to web service

    11-05-2008, 5:41 AM
    Answer

    you can't pass arraylist. you have to use object arrays.take an object array, pass all those arraylist values into objectlist. then pass that list.

     

     object[] oa = new object[al.length];

     for(int vLoop=0; vLoop<al.length; vLoop++)

    {

       oa[vLoop]  = al[vLoop];

    }

    then pass this oa to webservice.

     

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: Passing ArrayList to web service

    11-05-2008, 5:46 AM
    Answer
    • Contributor
      2,076 point Contributor
    • Erwin21
    • Member since 10-07-2008, 7:54 PM
    • Netherlands
    • Posts 338

    It's because of the interopability you can't pass ArrayLists via your webmethod, you have to convert you ArrayList to an other type e.g. a object array. For converting look at the ToArray method.

    More info at a similar thread: http://forums.asp.net/t/1210915.aspx

    Please remember to click “Mark as Answer” so I know if my answer was good enough for you. Thanks.
  • Re: Passing ArrayList to web service

    11-06-2008, 2:18 PM
    • Member
      2 point Member
    • feddo04
    • Member since 11-05-2008, 5:42 AM
    • Posts 2

    Thank you all....

    I preciated...

    I also solved this problem by converting the ArrayList to string and send it to webserver as string.

    But I believe that the sending by object is better than string.

    Thank you so much for helping me...

  • Re: Passing ArrayList to web service

    11-06-2008, 2:38 PM
    • Contributor
      2,076 point Contributor
    • Erwin21
    • Member since 10-07-2008, 7:54 PM
    • Netherlands
    • Posts 338

    Your welcome its great to help people :-)

    Please remember to click “Mark as Answer” so I know if my answer was good enough for you. Thanks.
  • Re: Passing ArrayList to web service

    07-03-2009, 2:35 AM
    • Member
      16 point Member
    • germaine.tay
    • Member since 09-22-2008, 7:02 AM
    • Singapore
    • Posts 128

    ramireddyindia:

    you can't pass arraylist. you have to use object arrays.take an object array, pass all those arraylist values into objectlist. then pass that list.


     object[] oa = new object[al.length];

     for(int vLoop=0; vLoop<al.length; vLoop++)

    {

       oa[vLoop]  = al[vLoop];

    }

    then pass this oa to webservice.




    Hi, I was trying to do your steps.

    Dim sc As New ArrayList //dim array list
    Dim ArrObj() As Object //create object
    ArrObj = sc.ToArray //convert to object AND PASS THIS TO WEB SERVICE.


    at the web service method im passing in string as a input parameter.

    Public Function DeleteRecord(ByVal EventDetailsID As string) As Integer

    didnt work at all.. please kindly help.

    thanks

    ---
    Regards,
    Germaine
  • Re: Passing ArrayList to web service

    07-04-2009, 12:00 AM

    Unless you're still stuck on .NET 1.1, you should not use the ArrayList class at all. Use one of the strongly-typed generic collections instead.

    John Saunders
Page 1 of 1 (7 items)