【发布时间】:2015-04-19 20:07:15
【问题描述】:
我必须在 ASP.NET 中实现一个 SOAP 1.1 Web 服务。我得到了请求和响应示例以及一个有问题的 wsdl 规范,当将其提供给 wsdl--> 代码向导时,它不会生成给出正确响应的代码。所以我坚持手动修复自动生成的 C# 代码。
这是其中一种方法必须产生的响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sws="http://something/WebService">
<soapenv:Header/>
<soapenv:Body>
<sws:MyActionResponse>
<sws:returnVariableOne>?</sws:returnVariableOne>
<sws:returnVariableTwo>?</sws:returnVariableTwo>
<sws:returnVariableThree>?</sws:returnVariableThree>
</sws:MyActionResponse>
</soapenv:Body>
</soapenv:Envelope>
我找不到如何让<sws:MyActionResponse> 按指定顺序包含多个元素。
我有这段代码在<sws:MyActionResponse> 元素下只产生一个子元素:
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://something/WebService/MyAction", RequestElementName="MyActionRequest", RequestNamespace="http://something/WebService", ResponseNamespace="http://something/WebService", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
[return: System.Xml.Serialization.XmlElementAttribute("returnVariableOne")]
public override string MyAction(string inputVariable)
{
return "Value of variable #1";
}
它的响应 xml 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<MyActionResponse xmlns="http://something/WebService">
<returnVariableOne>Value of variable #1</returnVariableOne>
</MyActionResponse>
</soap:Body>
</soap:Envelope>
嗯,我需要三个子元素,所以我正在寻找 C# 语法,它可以让 WebMethod 按规定的顺序返回几个元素的序列。我知道我可以返回一个包含复杂数据结构的复杂元素,但这无济于事,因为我必须匹配规范中给出的 xml 响应示例。
【问题讨论】:
-
为什么不把 Response 本身当作一个复杂的类型呢?
-
也许,但我不知道应该使用哪些属性和语法来覆盖 SOAP 响应消息元素。
-
我回顾了我过去使用的一项服务 - 示例响应的定义如下所示:pastebin.com/iAREa2Bg。为什么不附上 WSDL 以查看它有什么问题并修复它 - 它可能更容易?
-
抱歉,wsdl 不能分享,因为它涉及到商业应用,所以它是巨大的和机密的。
-
我明白了。没问题,很高兴你以某种方式解决了它。
标签: asp.net web-services soap