標籤:
最近使用WCF遇到一個問題:當用戶端向WCF服務發送一個大量資料時候,發現會提示:
"讀取 XML 資料時,超出最大字串內容長度配額 (8192)。通過更改在建立 XML 讀取器時所使用的 XmlDictionaryReaderQuotas 對象的 MaxStringContentLength 屬性,可增加此配額。" 於是上網搜尋,都說修改配置就可以,但我是初學者,修改半天還沒弄出來,最後各種整合,嘗試,終於成功了,於是記下了,以備以後需要:在設定檔內添加如下代碼就可以了(只需要修改服務端設定檔):
1.在 <system.serviceModel>節點下添加:
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" closeTimeout="10:10:00" openTimeout="10:10:00" receiveTimeout="10:10:00" sendTimeout="10:10:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="NewBehavior0" name="WcfService.GXSC.LoginService">
<endpoint binding="basicHttpBinding" contract="WcfService.GXSC.ILoginService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1379/GXSC/LoginService.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="NewBehavior0" name="WcfService.GXSC.ShipInfoService">
<endpoint binding="basicHttpBinding" contract="WcfService.GXSC.IShipInfoService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1379/GXSC/ShipInfoService.svc" />
</baseAddresses>
</host>
</service>
</services>
2.<behaviors>下 <serviceBehaviors>節點下添加如下:
<behavior name="NewBehavior0">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" maxConcurrentInstances="1000" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
就ok了
WCF用戶端傳輸大資料到服務端失敗配置問題