不止于此。
标准中存在一些可能导致互操作性问题的模糊性。您必须使用类型或元素,具体取决于您使用的是基于文档的服务还是基于 RPC 的服务。
也有歧义。如果你说
<wsdl:message name="message1" type="ns:type1"/>
那么您已经说过消息的内容必须针对类型“ns:type1”进行验证。但是您对包含内容的元素只字未提。它将在哪个命名空间中?
有关这方面的一些规则,请参阅WS-I Basic Profile。
cmets 中有一些关于“document/literal”与“document/literal/wrapped”的讨论。这是我的看法。
我刚刚创建了一个网络服务。以下是全部内容:
using System.Web.Services;
namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class SimpleMathService : WebService
{
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
[WebMethod]
public int Multiply(int a, int b)
{
return a*b;
}
}
}
我不会发布整个 WSDL,但这里是“好的部分”:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://tempuri.org/" xmlns:tns="http://tempuri.org/" >
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="Add">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="a" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="b" type="s:int"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AddResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1"
name="AddResult" type="s:int"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="int" type="s:int"/>
</s:schema>
</wsdl:types>
<wsdl:message name="AddSoapIn">
<wsdl:part name="parameters" element="tns:Add"/>
</wsdl:message>
<wsdl:message name="AddSoapOut">
<wsdl:part name="parameters" element="tns:AddResponse"/>
</wsdl:message>
<wsdl:portType name="SimpleMathServiceSoap">
<wsdl:operation name="Add">
<wsdl:input message="tns:AddSoapIn"/>
<wsdl:output message="tns:AddSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SimpleMathServiceSoap" type="tns:SimpleMathServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<soap:operation soapAction="http://tempuri.org/Add" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SimpleMathService">
<wsdl:port name="SimpleMathServiceSoap" binding="tns:SimpleMathServiceSoap">
<soap:address location="http://localhost:5305/SimpleMathService.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
请注意“包装”一词是如何不出现的。 IBM 在他们的文档中所说的“文档/文字/包装”只是“文档/文字”,它恰好使用单个消息部分,恰好有一个从服务名称派生的名称,并且恰好是指到一个元素,并且恰好包含操作的两个参数。
这里没有什么神奇的,这里没有什么不标准的。
在许多标准组织中,公司最终都偏袒一方。对于 SOAP,我们有“RPC 端”和“文档端”。 RPC 对很多人来说更为熟悉——它与函数调用一一对应。 Document 不太熟悉,需要您实际考虑简单的 XML。也许 IBM 在 RPC 方面,我不知道。
我现在已经完成了 IBM 文档,哪种 WSDL 样式。总结是:
总结
有四种绑定样式(确实有五种,但 document/encoded 没有意义)。虽然每种样式都有其位置,但在大多数情况下,最好的样式是文档/文字包装。
我还想根据消息中是否存在操作名称来对文档中讨论调度难度级别的地方做出反应。这是一个非问题。如果您阅读该文档,您会注意到它从未在 <binding> 部分讨论任何内容。 “无操作名”问题的解决办法就在那里。
<wsdl:binding name="SimpleMathServiceSoap" type="tns:SimpleMathServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<soap:operation soapAction="http://tempuri.org/Add" style="document"/>
soapAction 在请求的 HTTP 头中发送,可用于调度:
POST /SimpleMathService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Add"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add xmlns="http://tempuri.org/">
<a>int</a>
<b>int</b>
</Add>
</soap:Body>
</soap:Envelope>