获取响应结果作为数组而不是Web服务中的对象 [英] Getting the response result as an array and not a object in web service

查看:51
本文介绍了获取响应结果作为数组而不是Web服务中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个php应用程序,它将从我创建的Web服务中读取结果.他们想要的xml响应就像

There is a php application which will read the result from the web service i have created. The xml response they want is like

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <WorkResponse xmlns="http://tempuri.org/">
        <WorkResult>Name<WorkResult>
        <WorkResult>Occupation<WorkResult>
      </WorkResult>
    </WorkResponse>
  </s:Body>

但是我的方法返回的是这样的

But my method return like this `

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <WorkResponse xmlns="http://tempuri.org/">
      <WorkResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:string>Name</a:string>
        <a:string>Occupation</a:string>
      </WorkResult>
    </WorkResponse>
  </s:Body>`

下面是我在Web服务中编写的方法

And below is the method I have written in the web service

public string[] Work()
    {
        string[] request = new String[2];
        request[0] = "Name";
        request[1] = "Occupation";
        return request;
    }

我该怎么做才能得到他们想要的结果.请帮助我解决这个问题

How can I do to get the result they want. Please help me to come out of this issue

推荐答案

如果需要 WorkResult 节点同时包含 名称" 职业" ,并且在xml中的同一级别,您可以在WebMethod Work().这是一个示例:

If you need WorkResult node to contain both "Name" and "Occupation" and at the same level in the xml, you can achieve it returning a List in your WebMethod Work(). Here is an example:

public List<String> Work()
{
    public List<String> result = new List<String>();
    result.Add("Name");
    result.Add("Occupation");

    return result;
}

这篇关于获取响应结果作为数组而不是Web服务中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆