wcf soap消息反序列化错误 [英] wcf soap message deserialization error
问题描述
拨打服务电话时出现以下错误
I am getting following error when i make the service call
反序列化操作"IbankClientOperation"的请求消息正文时出错.OperationFormatter遇到无效的消息正文.预期会找到名称为"doClient_ws_IbankRequest"且名称空间为"http://www.informatica.com/wsdl/"的节点类型元素".找到名称为"string"且名称空间为"http://schemas.microsoft.com/2003/10/Serialization/"的节点类型元素"
Error in deserializing body of request message for operation 'IbankClientOperation'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'doClient_ws_IbankRequest' and namespace 'http://www.informatica.com/wsdl/'. Found node type 'Element' with name 'string' and namespace 'http://schemas.microsoft.com/2003/10/Serialization/'
我正在使用以下代码调用服务
i am using following code to call the service
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);
推荐答案
假设您的requestMessage在您的其他帖子中相同(似乎是这种情况,因为错误消息表明它正在接收字符串),因此您使用了不正确的Message.CreateMessage重载.您使用的是
Assuming your requestMessage is the same in your other post (which seems to be the case, since the error message says it's receiving a string), you're using an incorrect overload of Message.CreateMessage. The one you're using is defined as
Message.CreateMessage(MessageVersion version, string action, object body);
您传递给它的请求消息"是整个消息信封.您正在使用的这个代码将尝试序列化主体(并且由于它是字符串,因此它将序列化为< string xmlns ="http://schemas.microsoft.com/2003/10/Serialization/"> ...</string>
-准确地映射到您的错误消息.
And the "request message" you're passing to it is the whole message envelope. This one you're using will try to serialize the body (and since it's a string, it will serialize it as <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">...</string>
- which maps exactly to the error message you have.
由于已经有了SOAP信封,因此需要使用的是一种重载方法,例如下面的方法:
What you need to use, since you already have the SOAP envelope, is one overload which takes that, such as the one below:
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);
这篇关于wcf soap消息反序列化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!