文章出處
文章列表
在我們用WCF傳輸數據的時候,如果啟用默認配置,傳輸的數據量過大,經常會出這個錯誤。
WCF包含服務端與客戶端,所以這個錯誤可能出現在服務端返回數據給客戶端,或客戶端傳數據給服務端時。
1. 服務端返回數據給客戶端報錯
在客戶端配置文件中,主要是配置maxReceivedMessageSize
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="ServiceProxyBinding" closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxStringContentLength="134217728" /> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:5239/AHMTService/PartService.svc" binding="basicHttpBinding" bindingConfiguration="ServiceProxyBinding" contract="UniCloud.ServiceContracts.IPartService" name="IPartService" /> </client> </system.serviceModel>
2 客戶端傳數據給服務端報錯
修改服務端web.config,主要也是配置maxReceivedMessageSize
<system.serviceModel> <services> <!--DecodeService 服務端配置 增加接收文件大小--> <service name="UniCloud.Services.DecodeService" behaviorConfiguration="MyServiceBehaviour" > <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyServiceBinding" contract="UniCloud.ServiceContracts.IDecodeService"> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> <host> <baseAddresses> <add baseAddress="http://localhost:5239/AHMTService"/> </baseAddresses> </host> </service> </services> <bindings> <basicHttpBinding> <binding name="MyServiceBinding" closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <security mode="None"></security> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="MyServiceBehaviour"> <!-- 為避免泄漏元數據信息,請在部署前將以下值設置為 false --> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <!-- 要接收故障異常詳細信息以進行調試,請將以下值設置為 true。在部署前設置為 false 以避免泄漏異常信息 --> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <protocolMapping> <add binding="basicHttpsBinding" scheme="https" /> </protocolMapping> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel>
其實要修改所有的服務,不管是服務端還是客戶端,Binding那邊增加一個沒有設置名字的默認配置就OK了
<binding closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
文章列表
全站熱搜