Ask a Question related to ASP.NET Web Services, Design and Development.
-
Shawn Cutter #1
Return multiple values from web service
Background:
I am trying to return a list of ID's to the client requesting the web
service. The list of ID's I want to return is a list of all relating
ID's to the passed in PersonID.
How it currently functions:
Web Service (Server):
I have a basic web service that receives a PersonID. The webservice
then go to the DB to find all relating ID's. Currently I have the
result stored in a dataset. This however may be overkill since the
dataset consists of one datatable, which contains one column.
Client:
The client is a simple .NET page that uses the following to connect to
the webservice. proxy.PERSONREQUEST(PersonID)
I have successfully filled an array and can return one value from the
array using ( txtResult.Text = proxy.PERSONREQUEST(PersonID) ). How
can I return the entire result to the client all at once? I would like
to return it in the format of:
<PERSONRESULT>
<ID>ADS34579354</<ID>
<<ID>ASR34579354</<ID>
<<ID>TYU34579354</<ID>
</PERSONRESULT>
Am I approaching this whole thing wrong in using a dataset to fill an
array? Do I have to do something different on the client side so that
it knwo how to receive the list of values.
Any help would be appreciated.
Thanks,
Shawn
Shawn Cutter Guest
-
how return list values from web service
I am fairly new to web services and want to create a web service method in asp.net which will return a fixed size list of values. I am not sure how... -
vb.net consumer from a JAXM web service - blank return values
You will want to go to Doc/Literal instead of RPC/Encoded for best interoperability, according to the recommendations of the WS-I. Just looking... -
SQL - return only certain values?
I want to select only rows where the field 'category' contains the value NUTRITION. How is this done? -
function return values
If I assign a variable to a function, say, $x = f($y); and then f happens not to return anything, does $x just remain unset? Or is this illegal? -
Most efficient way to return multiple values to client
I'm writing an Active Directory web service and need to return multiple properties of a single user. The web service receives the username and... -
hellrazor #2
Re: Return multiple values from web service
"Shawn Cutter" <shawncutter@gmail.com> wrote in
news:1118330287.799343.224590@g14g2000cwa.googlegr oups.com:
Here's the simplest way to accomplish what you want. Have your webservice> Background:
> I am trying to return a list of ID's to the client requesting the web
> service. The list of ID's I want to return is a list of all relating
> ID's to the passed in PersonID.
>
> How it currently functions:
> Web Service (Server):
> I have a basic web service that receives a PersonID. The webservice
> then go to the DB to find all relating ID's. Currently I have the
> result stored in a dataset. This however may be overkill since the
> dataset consists of one datatable, which contains one column.
>
> Client:
> The client is a simple .NET page that uses the following to connect to
> the webservice. proxy.PERSONREQUEST(PersonID)
>
> I have successfully filled an array and can return one value from the
> array using ( txtResult.Text = proxy.PERSONREQUEST(PersonID) ). How
> can I return the entire result to the client all at once? I would like
> to return it in the format of:
>
> <PERSONRESULT>
> <ID>ADS34579354</<ID>
> <<ID>ASR34579354</<ID>
> <<ID>TYU34579354</<ID>
> </PERSONRESULT>
>
> Am I approaching this whole thing wrong in using a dataset to fill an
> array? Do I have to do something different on the client side so that
> it knwo how to receive the list of values.
>
> Any help would be appreciated.
>
> Thanks,
> Shawn
>
>
return a simple string array:
[WebMethod]
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)
{
Console.WriteLine(personId);
}
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:
[WebMethod]
public PersonResult getPersonIds()
{
PersonResult personResult = new PersonResult();
personResult.Ids.Add("ADS34579354");
personResult.Ids.Add("ASR34579354");
personResult.Ids.Add("TYU34579354");
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)
{
Console.WriteLine(personId);
}
Hope that helps!
Jorge
hellrazor Guest
-
hellrazor #3
Re: Return multiple values from web service
hellrazor <jorge@another-world.com> wrote in
news:Xns9670ABAABDF0Cjorgeanotherworldcom@207.46.2 48.16:
whoops.. made a mistake.. the PersonResult class should read as follows:> "Shawn Cutter" <shawncutter@gmail.com> wrote in
> news:1118330287.799343.224590@g14g2000cwa.googlegr oups.com:
>>>> Background:
>> I am trying to return a list of ID's to the client requesting the web
>> service. The list of ID's I want to return is a list of all relating
>> ID's to the passed in PersonID.
>>
>> How it currently functions:
>> Web Service (Server):
>> I have a basic web service that receives a PersonID. The webservice
>> then go to the DB to find all relating ID's. Currently I have the
>> result stored in a dataset. This however may be overkill since the
>> dataset consists of one datatable, which contains one column.
>>
>> Client:
>> The client is a simple .NET page that uses the following to connect
>> to the webservice. proxy.PERSONREQUEST(PersonID)
>>
>> I have successfully filled an array and can return one value from the
>> array using ( txtResult.Text = proxy.PERSONREQUEST(PersonID) ). How
>> can I return the entire result to the client all at once? I would
>> like to return it in the format of:
>>
>> <PERSONRESULT>
>> <ID>ADS34579354</<ID>
>> <<ID>ASR34579354</<ID>
>> <<ID>TYU34579354</<ID>
>> </PERSONRESULT>
>>
>> Am I approaching this whole thing wrong in using a dataset to fill an
>> array? Do I have to do something different on the client side so
>> that it knwo how to receive the list of values.
>>
>> Any help would be appreciated.
>>
>> Thanks,
>> Shawn
>>
>>
> Here's the simplest way to accomplish what you want. Have your
> webservice return a simple string array:
>
> [WebMethod]
> 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)
> {
> Console.WriteLine(personId);
> }
>
>
> 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:
>
> [WebMethod]
> public PersonResult getPersonIds()
> {
> PersonResult personResult = new PersonResult();
> personResult.Ids.Add("ADS34579354");
> personResult.Ids.Add("ASR34579354");
> personResult.Ids.Add("TYU34579354");
> 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)
> {
> Console.WriteLine(personId);
> }
>
>
> Hope that helps!
>
> Jorge
>
>
public class PersonResult
{
public ArrayList Ids = new ArrayList();
}
ArrayList is cast down to string[] or object[]
JOrge
hellrazor Guest
-
shawncutter@gmail.com #4
Re: Return multiple values from web service
Thanks alot Jorge. You cleared everything up for me.
Worked like a charm
Shawn
shawncutter@gmail.com Guest



Reply With Quote

