将名称空间从SOAP信封根目录移动到xml负载

时间:2009-07-15 20:01:37

标签: php soap namespaces wsdl

我有一个肥皂信封,它是从我编写的编码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有问题,只要它没有验证或类似的东西,只要忽略它......原来的验证/部署/工作正常。我更担心我可以放置名称空间的位置。谢谢!

1 个答案:

答案 0 :(得分:0)

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

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