WCF,流媒体,消息协定错误:在请求消息的身体反序列化错误 [英] WCF, Streaming, Message Contract Error: Error in deserializing body of request message

查看:1301
本文介绍了WCF,流媒体,消息协定错误:在请求消息的身体反序列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个有点复杂的WCF服务的方法。我想用流式传输模式,并且因为我有一个以上的参数,我已经定义了一个MessageContract具有主体和报头。

I have developed a bit of a complicated WCF Service method. I would like to use the Streaming transfer mode, and because I have more than one parameter, I have defined a MessageContract with a body and a header.

[MessageContract]
public class ReportAudioMessage
{
    [MessageHeader]
    public int ReportId;

    [MessageHeader]
    public string FileName;

    [MessageHeader]
    public int FileLengthInBytes;

    [MessageHeader]
    public int LengthInSeconds;

    [MessageBodyMember]
    public Stream ReportAudio;
}



注意流是身体的唯一成员,每个指引我读。MSDN

Notice the stream is the only member of the body, per guidelines I read on MSDN.

该方法的定义是这样的:

The method is defined as such:

    [OperationContract]
    void SaveReportAudio(ReportAudioMessage reportToSave);

当我试图调用方法(使用反射),我得到一个错误:

When I attempt to Invoke the method (using reflection), I get an error:

在错误反序列化的请求消息体运行
'SaveReportAudio。 OperationFormatter遇到无效的消息
身上。希望能够找到节点类型元素名为'SaveReportAudio'
和命名空间 http://tempuri.org/。发现节点类型元素与
名称'ReportAudioMessage'和命名空间
http://tempuri.org/

Error in deserializing body of request message for operation 'SaveReportAudio'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'SaveReportAudio' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'ReportAudioMessage' and namespace 'http://tempuri.org/'

SaveReportAudio是我打电话的服务方法的名称。 ReportAudioMessage是限定该MessageContract的名称。显然,我的SOAP消息是越来越抬高了,但我不知道如何...:(

SaveReportAudio is the name of the Service Method that I am calling. ReportAudioMessage is the name of the MessageContract that is defined. Clearly, my Soap Message is getting jacked up, but I don't know how... :(

以下是服务模式的节点,该服务的Web配置的

The following is the Service Model node, of the Service's web config:

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
    <bindings>
        <netTcpBinding>
            <binding
             name="VRManagerTcpBinding"
             closeTimeout="00:01:00"
             openTimeout="00:01:00"
             sendTimeout="00:01:00"
             receiveTimeout="00:01:00"
             transferMode="Streamed">
                <reliableSession enabled="false"/>
                <security mode="None" />
            </binding>
        </netTcpBinding>
    </bindings>
    <services>
        <service name="Radia.VoiceRecognition.Services.VRManager" behaviorConfiguration="VRManagerTcpBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="net.tcp://localhost:8011/VRManager"/>
                </baseAddresses>
            </host>
            <endpoint
             address="VRManager.svc"
             binding="netTcpBinding"
             bindingConfiguration="VRManagerTcpBinding"
             contract="Radia.VoiceRecognition.Services.IVRManager" />
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <behaviors>
       <serviceBehaviors>
        <behavior name="VRManagerTcpBehavior">
         <serviceMetadata httpGetEnabled="false" />
         <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior> 
       </serviceBehaviors>
      </behaviors>
</system.serviceModel>

这是客户端的App.Config中的服务模式节点:

And here is the Service Model node of the client's App.Config:

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IVRManager" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions"
      hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
      maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="None">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="net.tcp://xxxxxxxxxxx:8012/VRManager.svc/VRManager.svc"
    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IVRManager"
    contract="VRManager.IVRManager" name="NetTcpBinding_IVRManager" />
</client>



推荐答案

我能得到这个工作,虽然我不是很满意的解决方案。我觉得这是一个黑客,部分原因是因为我不完全理解它。

I was able to get this working, though I'm not happy with the solution. I feel like it is a hack, partly because I don't understand it completely.

琢磨的错误后,我决定启用WCF跟踪,看看我能找到。我看到XML消息,发现确实有元素的名称为ReportAudioMessage。所以,我决定修改邮件的合同,并设置WrapperName:

After pondering the error, I decided to enable WCF tracing and see what I could find. I saw the Xml message and noticed that indeed the element had the name "ReportAudioMessage". So, I decided to modify the message contract, and set the WrapperName:

[MessageContract(IsWrapped = true, WrapperName = "SaveReportAudio")]
public class ReportAudioMessage
{
    [MessageBodyMember]
    public Stream Session;
}



请注意WrapperName属性。现在,这是在我的WCF服务的方法的名称。现在它的工作原理。然而,这是令人沮丧的我,因为现在这个工作在两种方法 - 保存方法和get方法:

Notice the "WrapperName" property. Now, that is the name of the method on my WCF service. It now works. However, it is frustrating me because this works now on two methods - a save method and a get method:

[OperationContract]
void SaveReportAudio(ReportAudioMessage message);

[OperationContract]
ReportAudioMessage GetReportAudio(GetReportAudioRequestMessage request);



总之,这是为我工作,所以我只是用我下去。我将不胜感激任何进一步的评论或建议。谢谢,

Anyhow, it is working for me, so I just am going with it. I would appreciate any further comments or advice. Thanks,

这篇关于WCF,流媒体,消息协定错误:在请求消息的身体反序列化错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆