为什么dataContractSerializer不解决System.ServiceModel.Dispatcher.N
本文关键字:ServiceModel Dispatcher System 解决 dataContractSerializer 为什么 | 更新日期: 2023-09-27 18:10:11
在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>
bindingConfiguration应该与binding name相同。看看这里:WCF Service - System.ServiceModel.Dispatcher.NetDispatcherFaultException
您可以通过增加maxStringContentLength的值来避免异常。不需要行为