将响应结果作为数组而不是 Web 服务中的对象获取



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

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

但是我的方法像这样返回">

<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 服务中编写的方法

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

我该怎么做才能得到他们想要的结果。 请帮助我摆脱这个问题

如果您需要WorkResult节点同时包含"名称">"职业">并且在xml中处于同一级别,则可以在WebMethodWork()中返回List来实现它。下面是一个示例:

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

相关内容

最新更新