我尝试生成一个简单的 WCF 测试 SOAP 应用程序。一旦我在调试器中启动它,它就会打开一个浏览器到服务页面。该页面上有一个指向 wsdl ( http://.../MyService?wsdl
) 的链接。当我导航到该页面时,我看到了这个:
<wsdl:definitions name="MyService" targetNamespace="http://mynamespace.com/">
<wsdl:types>
<xsd:schema targetNamespace="http://mynamespace.com/Imports">
<xsd:import schemaLocation="http://localhost:59315/MyService.svc?xsd=xsd0" namespace="http://mynamespace.com/"/>
<xsd:import schemaLocation="http://localhost:59315/MyService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://localhost:59315/MyService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<xsd:import schemaLocation="http://localhost:59315/MyService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/My.Service"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IMyService_testConnection_InputMessage">
<wsdl:part name="parameters" element="tns:testConnection"/>
</wsdl:message>
<wsdl:message name="IMyService_testConnection_OutputMessage">
<wsdl:part name="parameters" element="tns:testConnectionResponse"/>
</wsdl:message>
<wsdl:message name="IMyService_testAction_InputMessage">
<wsdl:part name="parameters" element="tns:testAction"/>
</wsdl:message>
<wsdl:message name="IMyService_testAction_OutputMessage">
<wsdl:part name="parameters" element="tns:testActionResponse"/>
</wsdl:message>
<wsdl:portType name="IMyService">
<wsdl:operation name="testConnection">
<wsdl:input wsaw:Action="http://mynamespace.com/IMyService/testConnection" message="tns:IMyService_testConnection_InputMessage"/>
<wsdl:output wsaw:Action="http://mynamespace.com/IMyService/testConnectionResponse" message="tns:IMyService_testConnection_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="testAction">
<wsdl:input wsaw:Action="http://mynamespace.com/IMyService/testAction" message="tns:IMyService_testAction_InputMessage"/>
<wsdl:output wsaw:Action="http://mynamespace.com/IMyService/testActionResponse" message="tns:IMyService_testAction_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IMyService" type="tns:IMyService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="testConnection">
<soap:operation soapAction="http://mynamespace.com/IMyService/testConnection" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="testAction">
<soap:operation soapAction="http://mynamespace.com/IMyService/testAction" 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="MyService">
<wsdl:port name="BasicHttpBinding_IMyService" binding="tns:BasicHttpBinding_IMyService">
<soap:address location="http://localhost:59315/MyService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
将所有前缀映射到其模式的 xmlns 定义在哪里?
更具体地说,我的testAction
操作接受 2 个DateTime
对象和一个List<int>
. 当我深入研究链接的 xsd 时:
<xs:schema elementFormDefault="qualified" targetNamespace="http://rosscountgenerator.com/">
<xs:import schemaLocation="http://localhost:59315/MyService.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<xs:import schemaLocation="http://localhost:59315/MyService.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/My.Service"/>
<xs:element name="testConnection">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="value" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="testConnectionResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="testConnectionResult" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="testAction">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="startDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="endDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="storeIds" nillable="true" type="q1:ArrayOfint"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="testActionResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="testActionResult" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我看到List<int>
我的 storeIds 的类型是q1:ArrayOfint
. 但同样,没有映射。仔细看看,我可以假设http://schemas.microsoft.com/2003/10/Serialization/Arrays
架构实际上是正确的架构,当我查看那个 xsd 时:
<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<xs:complexType name="ArrayOfint">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="int" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfint" nillable="true" type="tns:ArrayOfint"/>
</xs:schema>
看来它是正确的地方。但是当我尝试触发请求时:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:msarray="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://mynamespace.com/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<my:testAction>
<my:startDate xsi:type="xsd:dateTime">2012-09-01T00:00:00</my:startDate>
<my:endDate xsi:type="xsd:dateTime">2012-09-15T00:00:00</my:endDate>
<msarray:storeIds xmlns:msarray="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
soapenc:arrayType="xsd:int[2]"
xsi:type="msarray:ArrayOfint">
<int xsi:type="xsd:int">1</int>
<int xsi:type="xsd:int">2</int>
</msarray:storeIds>
</my:testAction>
</soap:Body>
</soap:Envelope>
两个日期都很好,但 storeIds ( List<int>
) 为空。
是否有另一个文件包含所有xmlns
映射并且只包含所有这些?如果是这样,我在哪里可以找到它?另外,如果您知道为什么我的 List 实际上被反序列化为 null,我将不胜感激。
- - - - - - - - - - 更新 - - - - - - - - - - - -
对于我的具体问题,数组本身需要使用命名空间,my
并且数组的元素需要使用msarray
前缀命名空间:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:msarray="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://mynamespace.com/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<my:testAction>
<my:startDate xsi:type="xsd:dateTime">2012-09-01T00:00:00</my:startDate>
<my:endDate xsi:type="xsd:dateTime">2012-09-15T00:00:00</my:endDate>
<my:storeIds xmlns:msarray="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
soapenc:arrayType="xsd:int[2]"
xsi:type="msarray:ArrayOfint">
<msarray:int xsi:type="xsd:int">1</int>
<msarray:int xsi:type="xsd:int">2</int>
</my:storeIds>
</my:testAction>
</soap:Body>
</soap:Envelope>
现在它有效,但我的一般问题仍然存在。xmlns 声明在哪里?顺便说一句,再次感谢soapUI,它是解析 wsdl 不可或缺的工具。