wcf soap message deserialization error

a 夏天 提交于 2019-12-24 09:58:50

问题


I am getting following error when i make the service call

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);

回答1:


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);

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.

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);

And the code would look something like:

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);


来源:https://stackoverflow.com/questions/6263528/wcf-soap-message-deserialization-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!