Forum General

How to passing array to web service ?

OmarMohOmarMoh USMember ✭✭

Hello guy's

As you see in the title i have a problem in web service , i want to create method that receive array in parameter , and save ( insert ) array elements into database , How can i do this ? If you have any idea please comment bellow and thank for all

Best Answer


  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    You should implement a post method in your web service.
    You should not use a get method with parameters, if you want to upload real data (get should only be used for query some data ---> get some date and only pass some query parameter.)
    With a post method, you can define a data object (class) in your client and define the object as you need it (including e.g. lists -(> array's)).
    In your client, you then can fill the object, serialize the object as Json and pass the Json as parameter to the post method of the web service..
    In the web service you deserialize the Json again to a the object (if you have the same dev language for the client and the server (e.g. c# or, you just can copy-paste the data object and use it on both, client and server) and do what you want with the object (e.g. go thru a list and update your database).
    Search for your dev language and Json and post and you will find various examples.
    Hope this helps.. :sunglasses:

  • OmarMohOmarMoh USMember ✭✭

    Thanks my brother
    actullay i'am using Json for respons format in web service ( c# ) , in the client side i'm using Xamarin.forms
    i created method without parameter to retrieve data from database , i was defind class that containt the data and make it as a list ( List . . . . ) , i was retrieve data with json format and it's work in client side , but my problem is how to do the opposite to insert it into database. i well try your idea and thanks again

  • OmarMohOmarMoh USMember ✭✭

    List<myClass> ....

  • AuriAuri USMember ✭✭

    Here's a repo with a working API and working Xamarin.Forms consumer:

    It also shows off swapping out the web service access class with dependency resolver.


  • OmarMohOmarMoh USMember ✭✭

    Thanks @AuriRahimzadeh.0827 @FredyWenger and sorry for the late replay , I'm using Newtonsoft JSON and some codes and it's works fine :)

Sign In or Register to comment.