开发者

wcf soap message deserialization error

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开发者_JS百科();
    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);


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜