【问题标题】:Move namespace from SOAP envelope root to xml payload将命名空间从 SOAP 信封根移动到 xml 有效负载
【发布时间】:2010-11-11 03:25:51
【问题描述】:

我有一个从我编写的编码 RPC PHP 服务返回的肥皂信封,该服务在 SOAP 信封的根节点中声明了一个命名空间。但是,我希望该名称空间位于 SOAP 主体中 xml 有效负载的根节点中。基本上,我想要这个:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="http://sample.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org
/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:ServiceResponse>
       <outgoingVar1>true</outgoingVar1>
    </ns1:ServiceResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

变成这样:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org
/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-
ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ServiceResponse xmlns="http://sample.com">
       <outgoingVar1>true</outgoingVar1>
    </ServiceResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是我现在的注释(省略了琐碎的命名空间声明)WSDL:

<wsdl:definitions name="IJLSoapResponse" targetNamespace="http://casey.com" tns="http://casey.com" xmlns:samp="http://sample.com" ...>
<wsdl:types>
    <xsd:schema targetNamespace="http://casey.com" ...>
        <xsd:element name="incomingVar1" type="xsd:string" nillable="true"/>
        <xsd:element name="incomingVar2" type="xsd:string" nillable="true"/>
    </xsd:schema>
    <xsd:schema targetNamespace="http://sample.com" ...>
        <xsd:element name="outgoingVar1" type="xsd:boolean" nillable="true"/>
    </xsd:schema>
</wsdl:types>
<wsdl:message name="ServiceInput">
    <wsdl:part name="incomingVar1" element="tns:incomingVar1"/>
    <wsdl:part name="incomingVar2" element="tns:incomingVar2"/>
</wsdl:message>
<wsdl:message name="ServiceOutput">
    <wsdl:part name="outgoingVar1" element="samp:outgoingVar1"/>
</wsdl:message>
<wsdl:portType name="ServicePortType">
    <wsdl:operation name="ServiceMessage" parameterOrder="incomingVar1 incomingVar2">
        <wsdl:input name="ServiceMessageRequest" message="tns:ServiceInput"/>
        <wsdl:output name="ServiceMessageResponse" message="tns:ServiceOutput"/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ServiceBinding" type="tns:ServicePortType">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="ServiceMessage">
        <soap:operation soapAction="http://casey.com/soap/Service"/>
        <wsdl:input name="ServiceRequest">
            <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://casey.com"/>
        </wsdl:input>
        <wsdl:output name="ServiceResponse">
            <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://sample.com"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="ServiceService">
    <wsdl:port name="ServicePort" binding="tns:ServiceBinding">
        <soap:address location="http://casey.com/soap/Service"/>
    </wsdl:port>
</wsdl:service>
</wsdl:definitions>

是否可以更改 WSDL 中的某些内容以强制将该名称空间放入有效负载中?我试过把它搬到几个不同的地方,但无济于事。感谢您的帮助。

PS 如果您发现 WSDl 有问题,因为它没有被验证或类似的东西,请忽略它......原来的验证/部署/工作正常。我更担心我可以把命名空间放在哪里。谢谢!

【问题讨论】:

    标签: php soap namespaces wsdl


    【解决方案1】:

    命名空间的声明位置无关紧要,除非使用您的 SOAP 消息的代码做错了什么。

    由于“之前”和“之后”示例在功能上是等效的,因此它们在 WSDL 方面都是正确的,因此更改 WSDL 在这方面不会产生任何影响。

    【讨论】:

    • 这也是我最初的想法。所以,也许我问错了问题。使用代理的 WCF 客户端正在使用此服务的响应。像上面的第一个示例一样,soap 信封带有一个 true,但是当代理使用它时,该值出现 false。所以,我认为代理正在从肥皂包中剥离有效负载,因此 ns1 将不再具有声明的命名空间。我在吠叫错误的树吗?还有其他原因吗?
    • 击败我,因为我不熟悉 WCF :) 但是如果代理按照您的描述进行,那么它就是错误的。
    • 感谢您的帮助。我会将我的评论重新发布为 WCF 代理问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多