出現這個原因我們應該都能猜測到,文件傳出過大,超出了WCF預設範圍,那麼我們需要進行修改。 服務端和客戶端都需要修改。 第一、客戶端: 上面是wcf客戶端預設生成的,如需要修改傳輸文件大小,需要一下改動 <binding name="BasicHttpBinding_ITaskService" ma ...
出現這個原因我們應該都能猜測到,文件傳出過大,超出了WCF預設範圍,那麼我們需要進行修改。
服務端和客戶端都需要修改。
第一、客戶端:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_ITaskService" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:9001/wcf/TaskService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITaskService" contract="BZAService.ITaskService" name="BasicHttpBinding_ITaskService" /> </client> </system.serviceModel>
上面是wcf客戶端預設生成的,如需要修改傳輸文件大小,需要一下改動
<binding name="BasicHttpBinding_ITaskService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
第二、服務端:
<system.serviceModel> <services> <service name="BZACenterService.AssetService.TaskService"> <endpoint address="" binding="basicHttpBinding" contract="BZACenterService.AssetService.ITaskService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:8733/Design_Time_Addresses/BZACenterService.AssetService/TaskService/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
上面是服務端預設配置,我們發現並沒有bindings,如何設置那,方法是手動在<services>上增加如下
<bindings> <basicHttpBinding> <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" sendTimeout="00:10:00" /> </binding>
然後記得在在service 力的endpoint 增加屬性 bindingConfiguration="LargeDataTransferServicesBinding"
最終如下:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" sendTimeout="00:10:00" /> </basicHttpBinding> </bindings> <services> <service name="BZACenterService.AssetService.TaskService"> <endpoint address="" binding="basicHttpBinding" contract="BZACenterService.AssetService.ITaskService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:8733/Design_Time_Addresses/BZACenterService.AssetService/TaskService/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
第三、測試運行
最後編譯運行,正常調用wcf了。