我尝试生成一个简单的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>
我发现我的storeIds的List<int>
类型为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>
2个日期很好,但storeIds(List<int>
)为空。
是否有另一个包含所有xmlns
映射的文件,并且只包含所有这些?如果是这样,我在哪里可以找到它?此外,如果你有任何想法为什么我的列表实际上被反序列化为null我会非常感谢提示。
-------------------- UPDATE ----------------------- -
对于我的特定问题,数组本身需要使用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不可或缺的工具。