Return Array From WebService

Here’s the simplest way to accomplish what you want. Have your webservice return a simple string array:

public string[] getPersonIds(string Id)
//substitute code to actually populate the array with the dataset data
string[] personIds = {“ADS34579354”, “ASR34579354”, “TYU34579354”};
return personIds;

In the client:

//testWs = proxy object.
TestWs.TestWS testWs = new TestWs.TestWS();
string[] personIds = testWs.getPersonIds();
foreach (string personId in personIds)
If you actually want to return an object called “PersonResult” with named  instances of “ID” then here’s what you do:

in your WebServices code:

create a class called “PersonResult”, with the one single “Id” member,  declared as a primitive array:
class PersonResult
public string[] Id;
and your [WebMethod] function should look like this:

public PersonResult getPersonIds()
PersonResult personResult = new PersonResult();
return personResult;

in the client, here’s your code to obtain the instance of “PersonResult”  from the webservice:

TestWs.TestWS testWs = new TestWs.TestWS();
//define a variable of type TestWs.PersonResult, as defined by the proxy  class
TestWs.PersonResult personResult = testWs.getPersonIds();
foreach (string personId in personResult.Ids)
Hope that helps!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: