简体   繁体   English

如何反序列化带有名称空间前缀的soap请求?

[英]How to deserialize a soap request with a namespace prefix?

The first request works. 第一个请求有效。 The second returns a null in the arg0. 第二个在arg0中返回null。 The only difference is the namespace prefix "ns2". 唯一的区别是名称空间前缀“ ns2”。 The request with the prefix comes from an external source and can't be changed. 带有前缀的请求来自外部来源,无法更改。

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><putEvent xmlns="http://xxx.xxx.x.xx/">
<arg0>test</arg0>
</putEvent></S:Body>
</S:Envelope>


<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:putEvent xmlns:ns2="http://xxx.xxx.x.xx/">
<arg0>test</arg0>
</ns2:putEvent></S:Body>
</S:Envelope>

How to handle such a request properly? 如何正确处理这样的请求? For now the code handling it is generated from the wsdl. 目前,代码处理是从wsdl生成的。

The wsdl: wsdl:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://swd.ws.siwcpr.wasko.pl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="MockService" targetNamespace="http://swd.ws.siwcpr.wasko.pl/">
<wsdl:types>
<xsd:schema targetNamespace="http://swd.ws.siwcpr.wasko.pl/Imports">
<xsd:import schemaLocation="http://192.168.5.77:8733/SWDMockService/?xsd=xsd2" namespace="http://swd.ws.siwcpr.wasko.pl/"/>
<xsd:import schemaLocation="http://192.168.5.77:8733/SWDMockService/?xsd=xsd0" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
<xsd:import schemaLocation="http://192.168.5.77:8733/SWDMockService/?xsd=xsd1" namespace="http://schemas.datacontract.org/2004/07/Siwcpr.Simulators.Swd.MockService.SwdServiceRef"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="pingRequest">
<wsdl:part name="ping" element="tns:ping"/>
</wsdl:message>
<wsdl:message name="pingResponse">
<wsdl:part name="pingResponse" element="tns:pingResponse"/>
</wsdl:message>
<wsdl:message name="putEventRequest">
<wsdl:part name="putEvent" element="tns:putEvent"/>
</wsdl:message>
<wsdl:message name="putEventResponse">
<wsdl:part name="putEventResponse" element="tns:putEventResponse"/>
</wsdl:message>
<wsdl:message name="notifyDictionaryChangeRequest">
<wsdl:part name="notifyDictionaryChange" element="tns:notifyDictionaryChange"/>
</wsdl:message>
<wsdl:message name="notifyDictionaryChangeResponse">
<wsdl:part name="notifyDictionaryChangeResponse" element="tns:notifyDictionaryChangeResponse"/>
</wsdl:message>
<wsdl:portType name="IMockService">
<wsdl:operation name="ping">
<wsdl:input wsaw:Action="http://swd.ws.siwcpr.wasko.pl/WsdWsService/pingRequest" name="pingRequest" message="tns:pingRequest"/>
<wsdl:output wsaw:Action="http://swd.ws.siwcpr.wasko.pl/WsdWsService/pingResponse" name="pingResponse" message="tns:pingResponse"/>
</wsdl:operation>
<wsdl:operation name="putEvent">
<wsdl:input wsaw:Action="http://swd.ws.siwcpr.wasko.pl/WsdWsService/putEventRequest" name="putEventRequest" message="tns:putEventRequest"/>
<wsdl:output wsaw:Action="http://swd.ws.siwcpr.wasko.pl/WsdWsService/putEventResponse" name="putEventResponse" message="tns:putEventResponse"/>
</wsdl:operation>
<wsdl:operation name="notifyDictionaryChange">
<wsdl:input wsaw:Action="http://swd.ws.siwcpr.wasko.pl/WsdWsService/notifyDictionaryChangeRequest" name="notifyDictionaryChangeRequest" message="tns:notifyDictionaryChangeRequest"/>
<wsdl:output wsaw:Action="http://swd.ws.siwcpr.wasko.pl/WsdWsService/notifyDictionaryChangeResponse" name="notifyDictionaryChangeResponse" message="tns:notifyDictionaryChangeResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IMockService" type="tns:IMockService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ping">
<soap:operation soapAction="http://swd.ws.siwcpr.wasko.pl/WsdWsService/pingRequest" style="document"/>
<wsdl:input name="pingRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="pingResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="putEvent">
<soap:operation soapAction="http://swd.ws.siwcpr.wasko.pl/WsdWsService/putEventRequest" style="document"/>
<wsdl:input name="putEventRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="putEventResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="notifyDictionaryChange">
<soap:operation soapAction="http://swd.ws.siwcpr.wasko.pl/WsdWsService/notifyDictionaryChangeRequest" style="document"/>
<wsdl:input name="notifyDictionaryChangeRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="notifyDictionaryChangeResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MockService">
<wsdl:port name="BasicHttpBinding_IMockService" binding="tns:BasicHttpBinding_IMockService">
<soap:address location="http://192.168.5.77:8733/SWDMockService/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

I suppose you talking about WCF service/client. 我想您在谈论WCF服务/客户端。 So you have to extend your service/client with a behavior IEndpointBehavior . 因此,您必须使用行为IEndpointBehavior扩展服务/客户端。 You have to realize IDispatchMessageInspector / IClientMessageInspector wich would inspect request message and correct it with required namespace prifix. 您必须意识到IDispatchMessageInspector / IClientMessageInspector可以检查请求消息并使用所需的名称空间prifix对其进行更正。 Here is a good explanation. 是一个很好的解释。

Without seeing the full XSD for each imported schema it might be hard to say, but I believe the problem is this: 如果没有看到每个导入模式的完整XSD,可能很难说,但是我相信问题是这样的:

<S:Body><ns2:putEvent xmlns:ns2="http://xxx.xxx.x.xx/">
<arg0>test</arg0> <--- here
</ns2:putEvent></S:Body>

The issue is that in the first case that does work, arg0 is also included in the http://xxx.xxx.x.xx by the implicit namespace inclusion, while on the second, <putEvent> is in the right namespace, but <arg0> is not. 问题在于,在第一种可行的情况下,arg0也通过隐式命名空间包含项包含在http://xxx.xxx.x.xx中 ,而在第二种情况下,<putEvent>在正确的命名空间中,但是<arg0>不是。

So the client is actually generating the wrong request, it should be issuing this: 因此,客户端实际上生成了错误的请求,应该发出以下命令:

<S:Body><ns2:putEvent xmlns:ns2="http://xxx.xxx.x.xx/">
<ns2:arg0>test</ns2:arg0> <--- here
</ns2:putEvent></S:Body>

HTH, HTH,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM