出现这个原因我们应该都能猜测到,文件传出过大,超出了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了。