Return multiple values from web service

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. SQL - return only certain values?
      I want to select only rows where the field 'category' contains the value NUTRITION. How is this done?
    4. 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?
    5. 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...
  3. #2

    Default Re: Return multiple values from web service

    "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

    hellrazor Guest

  4. #3

    Default Re: Return multiple values from web service

    hellrazor <jorge@another-world.com> wrote in
    news:Xns9670ABAABDF0Cjorgeanotherworldcom@207.46.2 48.16:
    > "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
    >
    >
    whoops.. made a mistake.. the PersonResult class should read as follows:

    public class PersonResult
    {
    public ArrayList Ids = new ArrayList();
    }


    ArrayList is cast down to string[] or object[]

    JOrge
    hellrazor Guest

  5. #4

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139