【问题标题】:WCF client proxy mishandling returned SOAP envelopeWCF 客户端代理错误处理返回的 SOAP 信封
【发布时间】:2009-07-15 21:30:53
【问题描述】:

我有一个 RPC 编码的 PHP 网络服务,它返回一个带有布尔数据类型的简单肥皂信封。在客户端进行跟踪时,soap 信封在进入 WCF 代理之前看起来像这样:

<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:ServiceMessageResponse>
       <outgoingVar1>true</outgoingVar1>
    </ns1:ServiceMessageResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是,当返回值从代理的另一端传出时,它已更改为 false。我尝试将 xsi:type="xsd:boolean" 添加到传出Var1,但这没有帮助。肥皂信封本身正是客户所期望的,但由于某种原因,它不能正确使用它。这与 PHP Web 服务的设置方式有关还是在 WCF 代理中? PHP web 服务的简单设置如下:

ini_set('soap.wsdl_cache_enabled', '0');
ini_set('soap.wsdl_cache_ttl', '0');
$soapServer = new SoapServer('wsdl/sample.wsdl', array('soap_version' => SOAP_1_1));
$soapServer->addFunction('Service');
$soapServer->handle();

并且函数以简单的'return true;'结束线。这里没有什么复杂的。任何想法可能是什么问题?

带注释的 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="ServiceMessageRequest">
                    <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://casey.com"/>
            </wsdl:input>
            <wsdl:output name="ServiceMessageResponse">
                    <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>

这应该足以了解事物是如何声明的...如果您需要澄清其他任何内容,请告诉我。感谢您的帮助!

【问题讨论】:

  • 你在 WCF 方面的合同是什么样的?
  • @caseycrites:我需要查看一些 WCF 代码才能将 2 和 2 放在一起。我会把这个转给其他一些可能的人。
  • WCF 合同是合作伙伴的代码,所以我不认为我可以得到它......或者在这里发布它。对不起...
  • 关于发布 WSDL 的建议。不要删除琐碎的命名空间——这意味着我必须将它们添加回来才能使用它。不要放“...”或任何其他无效的 XML。如果你想要这样的东西,请使用评论。
  • 你在这方面有所收获吗?

标签: php wcf soap wsdl client


【解决方案1】:

我们可以查看服务的 WSDL 吗?我想知道outingVar1 的命名空间是什么。

RPC 编码的服务一直很痛苦,因为对于哪些命名空间消息部分的含义不明确。看到这就是这里的问题,我不会感到惊讶。


以下绑定似乎在soapUI 中有效。至少,它可以生成一个模拟服务,并且响应消息看起来像您要查找的内容(示例命名空间中的 outgoingVar1):

<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="ServiceMessageRequest">
            <soap:body parts="incomingVar1 incomingVar2" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://casey.com"/>
        </wsdl:input>
        <wsdl:output name="ServiceMessageResponse">
            <soap:body parts="outgoingVar1" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://sample.com"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

【讨论】:

  • outgoingVar1 应该是 sample.com...in 的一部分,soap 信封不应该 ns1 (sample.com) 传播给 ServiceResponse 的子代?
  • 没有。命名空间不会那样传播。它需要一个 xmlns="sample.com" 才能做到这一点(使 sample.com 成为未来的默认命名空间)。 ns1 仅适用于它所使用的元素。
  • 我用 XMLSpy 和soapUI 玩了一下WSDL。 soapUI 不喜欢它。似乎希望输入和输出名称在 portType 和绑定之间匹配。
  • John:感谢您到目前为止的帮助,从现在开始,我将确保并保留命名空间。 WSDL 上的不匹配是我在上面修复的一个编辑错误。我将parts 属性添加到soap:body 节点,但它根本没有改变输出SOAP 信封的外观。它仍然是无前缀的。
  • 当我在soapUI 中生成一个模拟服务时,我确实得到了作为正确命名空间的一部分的传出Var1。但是,当我使用相同的 WSDL 访问实际服务时,它只返回带有前缀的 ServiceMessageResponse。 PHP 服务本身的声明中是否缺少某些内容?
【解决方案2】:

解决方案最终处理了命名空间。由于它们没有正确传播,我需要将属性 elementFormDefault="qualified" 添加到架构中。这会强制前缀出现在每个元素上,这是我能让 .NET 满意的唯一方法。感谢您在这方面的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 2019-02-09
    • 2022-07-04
    • 2018-03-21
    • 1970-01-01
    相关资源
    最近更新 更多