我有一个带有以下web.config的WCF服务:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataExchange">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="LargeHttpBinding" maxBufferSize="5064536" maxBufferPoolSize="5064536" maxReceivedMessageSize="5064536">
<readerQuotas maxDepth="32" maxStringContentLength="5064536" maxArrayLength="5064536" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MetadataExchange" name="Service.Interface.ApplicationService.ApplicationService">
<endpoint name="httpEndpoint" address="" binding="basicHttpBinding" bindingConfiguration="LargeHttpBinding" contract="Service.Proxy.ApplicationService.Interfaces.IApplicationService" />
<endpoint name="mexEndpoint" address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:15000/"/>
</baseAddresses>
</host>
</service>
</services>
<client>
<endpoint name="httpEndpoint" address="http://localhost:15000/ApplicationService/ApplicationService.svc" binding="basicHttpBinding" bindingConfiguration="LargeHttpBinding" contract="Service.Proxy.ApplicationService.Interfaces.IApplicationService" />
</client>
</system.serviceModel>
<system.webServer>
<!--ToDo: Set directory browse to false-->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
该服务应该能够接收5MB +开销消息(我将图片作为字节数组发送到服务器)。
在客户端,我使用带有以下BasicHttpBinding的ChannelFactory:
basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.MaxBufferSize = 5064536;
basicHttpBinding.MaxBufferPoolSize = 5064536;
basicHttpBinding.MaxReceivedMessageSize = 5064536;
basicHttpBinding.ReaderQuotas.MaxDepth = 32;
basicHttpBinding.ReaderQuotas.MaxStringContentLength = 5064536;
basicHttpBinding.ReaderQuotas.MaxArrayLength = 5064536;
basicHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
basicHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
如果我尝试发送大小约为150kb的图片,则会显示错误消息,并显示以下消息:
远程服务器返回了意外响应:(413)Request Entity Too Large。