为什么dataContractSerializer没有解析System.ServiceModel.Dispatcher.NetDispatcherFaultException?

时间:2014-06-24 04:48:26

标签: c# xml wcf app-config datacontractserializer

在WCF应用程序中使用XML时出现以下异常:

System.ServiceModel.Dispatcher.NetDispatcherFaultException:格式化程序抛出 尝试反序列化消息时出现异常:

添加DataContractSerializer的以下部分后,它不起作用。仍然得到错误。添加DataContractSerializer后,我的app.config看起来像这样:

configuration>
<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="Graph">
        <dataContractSerializer maxItemsInObjectGraph="1000000000"/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
    <bindings>

        <basicHttpBinding>

            <binding name="BasicHttpBinding_IBrokerService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>

            </binding>

        </basicHttpBinding>

    </bindings>
    <client>
      <endpoint address="http://mx4p2/test1/test2.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_TestService" contract="Proxy.TestService"
          name="BasicHttpBinding_TestService" behaviorConfiguration="Graph" />
    </client>



</system.serviceModel>

2 个答案:

答案 0 :(得分:0)

bindingConfiguration应该与绑定名称相同。看看这里: WCF Service - System.ServiceModel.Dispatcher.NetDispatcherFaultException

答案 1 :(得分:0)

只需增加maxStringContentLength的值即可避免异常。不需要行为。