WCF从客户端向服务器传送大数据的问题
调用WCF向服务器传送数据。
报错
读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。 第 64 行,位置为 79。
网上找到很多解决方法都是设置MaxStringContentLength。但是都设置还是不好使。
客户端app.config修改:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ShareService" 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="2097152"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<!-- Reset maxStringContentLength for deserialize -->
<readerQuotas maxDepth="32" maxStringContentLength="2097152" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
服务端web.config修改:
<system.serviceModel>
<!-- add for the message size -->
<bindings>
<basicHttpBinding>
<binding name="NewBinding2MB" maxReceivedMessageSize="2097152">
<readerQuotas maxStringContentLength="2097152" />
</binding>
</basicHttpBinding>
</bindings>
<!-- add for the message size -->
<behaviors>
<serviceBehaviors>
<behavior name="Web.WCF.ShareServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Web.WCF.ShareServiceBehavior" name="Web.WCF.ShareService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding2MB" contract="Web.WCF.ShareService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
[最优解释]
你在WCF里新建一个函数,然后重新编译一下,然后在客户端重新引用一下WCF。看看能不能调用你新建的这个方法。你编译的和引用的有可能不是一个WCF。
[其他解释]
maxBufferSize="65536"
maxBufferSize="再整大一点"
[其他解释]
客户端和服务端都要做一致的大小配置