【问题标题】:wcf soap message deserialization errorwcf soap 消息反序列化错误
【发布时间】:2011-09-09 22:46:41
【问题描述】:

我在拨打服务电话时遇到以下错误

反序列化操作“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);

【问题讨论】:

  • 我认为您需要向我们展示您的 requestMessage 参数被传递给 Message.CreateMessage。看来您的内容根本不符合另一端预期的消息架构。

标签: wcf serialization soap deserialization


【解决方案1】:

假设您的 requestMessage 在your other post 中是相同的(似乎是这种情况,因为错误消息说它正在接收一个字符串),那么您使用的 Message.CreateMessage 重载不正确。您正在使用的定义为

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

您传递给它的“请求消息”是整个消息信封。您正在使用的这个将尝试序列化正文(并且由于它是一个字符串,它会将其序列化为 &lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;...&lt;/string&gt; - 它完全映射到您的错误消息。

由于您已经拥有 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);

【讨论】:

  • 我如何指定调用哪个方法,因为 CreateMessage 的这个重载没有动作名称的任何参数..
  • Yippee....我得到了解决方案...我添加了一个 SOAPAction http 标头并将我的 ActionName 作为值...谢谢 Carlosfigueira :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多