客户端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ImportAndExportWcfService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1973/OMSGIS/WcfService/ImportAndExportWcfService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ImportAndExportWcfService"
contract="WcfService.ImportExport.ImportAndExportWcfService"
name="BasicHttpBinding_ImportAndExportWcfService" />
</client>
</system.serviceModel>
服务端配置:
<configuration>
<system.web>
<!--这里的单位是KB,这样就可以传100M的文件了-->
<httpRuntime maxRequestLength="102400" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService.ImportAndExportWcfService">
<!--为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ImportAndExportWcfService" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00"
sendTimeout="00:10:00">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647"
maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="WcfService.ImportAndExportWcfService" behaviorConfiguration="WcfService.ImportAndExportWcfService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ImportAndExportWcfService" contract="WcfService.ImportAndExportWcfService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
</configuration>
注:
.net默认只能传4M的文件,所以尽管设定了Wcf两端的配置,还是超不出.net的限定,所以如果要传输大文件,还需要在System.Web节下加上
<httpRuntime maxRequestLength="102400" />