为什么 XML 命名空间在此 XML SOAP 请求中不是不需要的?
Why XML namespace is not unwanted in this XML SOAP request?
我不明白为什么以下 XML(根据 WSDL 请求构建)无效:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body xmlns:m="https://test.com/schemas/Plat/">
<m:TestRequest>
<m:transactId>TRANS_46151</m:transactId>
<m:param1>paramvalue1</m:param1>
</m:TestRequest>
</soap:Body>
</soap:Envelope>
以及为什么一旦从 "TestRequest" 参数中删除 "m" 命名空间后它就变得有效,如下所示:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body xmlns:m="https://test.com/schemas/Plat/">
<m:TestRequest>
<transactId>TRANS_46151</transactId>
<param1>paramvalue1</param1>
</m:TestRequest>
</soap:Body>
</soap:Envelope>
注意:XSD 是:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema attributeFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://test.com/schemas/Plat/"
<xsd:complexType name="EnteteMessageType">
<xsd:sequence>
<xsd:element name="transactId" type="xsd:string" minOccurs="0" />
<xsd:element name="param1" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="TestRequest" type="EnteteMessageType" />
</xsd:schema>
感谢您的帮助。
可能是因为您没有将元素形式指定为“qualified”:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://test.com/schemas/Plat/"
xmlns:tns="https://test.com/schemas/Plat/">
<xsd:complexType name="EnteteMessageType">
<xsd:sequence>
<xsd:element name="transactId" type="xsd:string" minOccurs="0" />
<xsd:element name="param1" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="TestRequest" type="tns:EnteteMessageType" />
</xsd:schema>
我不明白为什么以下 XML(根据 WSDL 请求构建)无效:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body xmlns:m="https://test.com/schemas/Plat/">
<m:TestRequest>
<m:transactId>TRANS_46151</m:transactId>
<m:param1>paramvalue1</m:param1>
</m:TestRequest>
</soap:Body>
</soap:Envelope>
以及为什么一旦从 "TestRequest" 参数中删除 "m" 命名空间后它就变得有效,如下所示:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body xmlns:m="https://test.com/schemas/Plat/">
<m:TestRequest>
<transactId>TRANS_46151</transactId>
<param1>paramvalue1</param1>
</m:TestRequest>
</soap:Body>
</soap:Envelope>
注意:XSD 是:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema attributeFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://test.com/schemas/Plat/"
<xsd:complexType name="EnteteMessageType">
<xsd:sequence>
<xsd:element name="transactId" type="xsd:string" minOccurs="0" />
<xsd:element name="param1" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="TestRequest" type="EnteteMessageType" />
</xsd:schema>
感谢您的帮助。
可能是因为您没有将元素形式指定为“qualified”:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://test.com/schemas/Plat/"
xmlns:tns="https://test.com/schemas/Plat/">
<xsd:complexType name="EnteteMessageType">
<xsd:sequence>
<xsd:element name="transactId" type="xsd:string" minOccurs="0" />
<xsd:element name="param1" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="TestRequest" type="tns:EnteteMessageType" />
</xsd:schema>