有一个 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>`
下面是我在网络服务中编写的方法
public string[] Work()
{
string[] request = new String[2];
request[0] = "Name";
request[1] = "Occupation";
return request;
}
我该怎么做才能得到他们想要的结果。
请帮助我解决这个问题
如果你需要WorkResult
包含两者的节点"Name" and “职业”在 xml 的同一级别,您可以实现它返回List
在您的 WebMethod 中Work()
。这是一个例子:
public List<String> Work()
{
public List<String> result = new List<String>();
result.Add("Name");
result.Add("Occupation");
return result;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)