Search code examples
c#asp.netweb-servicesjax-wswebclient

Return object which contains List<object> to web client in C#


I have JAX-WS web method that returns an object that contains list of objects. I am trying to consume this method from asp.net web client. How can I access the returned object? Should I bother about raw xml SOAP response? Can anyone point out where I should look for the solution to this problem? Thank you

Here's my web method:

@WebMethod(operationName = "searchPerson")
public People searchPerson(@WebParam(name = "ID") int ID) {
    People ppl = new People();
    List<Person> pDetails= ppl.getPersonDetails();
//my implementation
return ppl;

And here's the soap response:

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <S:Body>
        <ns2:searchPersonResponse xmlns:ns2="http://People/" xmlns:ns3="http://xml.netbeans.org/schema/Person">
            <return>
                <ns3:person_details>
                    <ns3:id>10012</ns3:id>
                    <ns3:Name>Bob</ns3:Name>
                </ns3:person_details>
            </return>
        </ns2:searchPersonResponse>
    </S:Body>
</S:Envelope>

And my webclient:

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void searchBtn_Click(object sender, EventArgs e)
        {
            LookupService.PeopleWSClient client = new LookupService.PeopleWSClient();
            LookupService.searchPersonResponse searchResponse = new LookupService.searchPersonResponse();
            client.searchPerson(Convert.ToInt32(searchTxt.Text));
        }
    }
}

Solution

  • I found a solution. I just needed to instantiate an object of webservice on my client. Helpful tutorial found here Sending list from webservice and consume it in application, and related How to add web reference