2014-09-29 107 views
1

第一個請求起作用。第二個返回arg0中的空值。唯一的區別是命名空間前綴「ns2」。帶有前綴的請求來自外部來源,無法更改。如何使用名稱空間前綴反序列化soap請求?

<?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> 

如何正確處理這樣的請求?現在處理它的代碼是從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> 
+0

什麼是您的WSDL樣子? – tomasr 2014-09-29 10:28:40

+0

添加了我的服務當前生成的WSDL – user3185092 2014-09-29 11:42:06

回答

0

我想你說的是WCF服務/客戶端。因此,您必須使用行爲IEndpointBehavior來擴展您的服務/客戶端。你必須認識到IDispatchMessageInspector/IClientMessageInspector這將檢查請求消息,並與所需的命名空間prifix糾正它。 Here是一個很好的解釋。

0

沒有看到完整的XSD每個導入的模式可能很難說,但我相信這個問題是這樣的:

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

的問題是,在沒有工作的第一種情況下,爲arg0也包含在http://xxx.xxx.x.xx中由隱式命名空間包含,而第二個,<putEvent>位於正確的命名空間中,但<arg0>不是。

因此客戶實際上是產生了錯誤的請求,應當發出這樣的:

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

HTH,

+0

它確實有意義,這可能是問題,但請求仍然無法更改。 – user3185092 2014-09-29 14:33:47

相關問題