在C#中将包含List <object>的对象返回给Web客户端

时间:2016-01-29 12:34:07

标签: c# asp.net web-services jax-ws webclient

我有JAX-WS Web方法,它返回一个包含对象列表的对象。我试图从asp.net Web客户端使用此方法。如何访问返回的对象?我应该打扰原始的xml SOAP响应吗? 任何人都可以指出我应该寻找解决这个问题的方法吗?谢谢

这是我的网络方法:

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

这是肥皂回应:

<?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>

我的网络客户:

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));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我只需要在我的客户端上实例化webservice的对象。有用的教程Sending list from webservice and consume it in application和相关的How to add web reference