2011-06-07 122 views
1

我收到以下錯誤,當我讓服務電話WCF SOAP消息反序列化錯誤

錯誤在反序列化請求消息的身體操作「IbankClientOperation」。 OperationFormatter遇到無效的消息體。預計會找到名稱爲「doClient_ws_IbankRequest」和命名空間「http://www.informatica.com/wsdl/」的節點類型「元素」。發現節點類型「元素」名爲「串」和命名空間「http://schemas.microsoft.com/2003/10/Serialization/」

我使用下面的代碼來調用服務

Message requestMsg = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IService1/IbankClientOperation", requestMessage); 

    Message responseMsg = null; 

    BasicHttpBinding binding = new BasicHttpBinding(); 
    IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>(); 
    channelFactory.Open(); 

    EndpointAddress address = new EndpointAddress(this.Url); 
    IRequestChannel channel = channelFactory.CreateChannel(address); 
    channel.Open(); 

    responseMsg = channel.Request(requestMsg); 
+0

我認爲你需要向我們展示你的requestMessage參數傳遞Message.CreateMessage。看起來你的內容根本不會c通知另一端預期的消息模式。 – 2011-06-07 12:44:16

回答

0

假設您的requestMessage在your other post(這似乎是這種情況,因爲錯誤消息表示它接收到一個字符串)相同,您正在使用Message.CreateMessage的不正確重載。您正在使用的是定義爲

Message.CreateMessage(MessageVersion version, string action, object body); 

而您傳遞給它的「請求消息」是整個消息信封。這個你正在使用的將嘗試序列化正文(因爲它是一個字符串,它會將其序列化爲<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">...</string> - 它完全映射到您所擁有的錯誤消息中)

您需要使用什麼,因爲您已經擁有SOAP信封,是一個重載這需要的是,如下面的一個:

Message.CreateMessage(XmlReader enveloperReader, int maxSizeOfHeaders, MessageVersion version); 

,代碼會看起來像:

string requestMessageString = @"<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns:inf="http://www.informatica.com/" 
     xmlns:wsdl="http://www.informatica.com/wsdl/"> 
    <soapenv:Header> 
     <inf:Security> 
      <UsernameToken> 
       <Username>john</Username> 
       <Password>jhgfsdjgfj</Password> 
      </UsernameToken> 
     </inf:Security> 
    </soapenv:Header> 
    <soapenv:Body> 
     <wsdl:doClient_ws_IbankRequest> 
      <wsdl:doClient_ws_IbankRequestElement> 
       <!--Optional:--> 
       <wsdl:Client_No>00460590</wsdl:Client_No> 
      </wsdl:doClient_ws_IbankRequestElement> 
     </wsdl:doClient_ws_IbankRequest> 
    </soapenv:Body> 
</soapenv:Envelope>"; 

XmlReader envelopeReader = XmlReader.Create(new StringReader(requestMessageString)); 
Message requestMsg = Message.CreateMessage(envelopeReader, int.MaxValue, MessageVersion.Soap11); 
+0

我該如何指定要調用的方法,因爲CreateMessage的這個重載沒有任何行爲名稱的參數.. – 2011-06-08 06:12:45

+0

Yippee ....我得到了解決方案...我添加了一個SOAPAction http頭並給了我的ActionName值。謝謝你Carlosfigueira :) – 2011-06-08 08:50:19