WCF服务默认处理的最大消息大小:65536字节,
如果需要服务可以接受更大的数据消息,可以通过web.config修改配置信息:
<httpRuntime targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=********" executionTimeout="300" maxRequestLength="10240" />
<bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IDotNetWebService" /> <binding name="BasicHttpBinding_IPdsService" /> </basicHttpBinding> <webHttpBinding> <!-- Limits set to 10 MB (specified value in bytes) --> <binding name="ApiQuotaBinding" maxReceivedMessageSize="10485760" maxBufferPoolSize="10485760" maxBufferSize="10485760" > <readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="10485760" maxBytesPerRead="10485760" /> <security mode="None" /> </binding> </webHttpBinding> </bindings>
然后在endpoint上指定bindingConfiguration:
<services> <service name="MobilePlatWcfService.Web.Services.MobileRestWebService"> <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="ApiQuotaBinding" contract="MobilePlatWcfService.Web.Services.IMobileRestWebService" /> </service> </services>
======================================
下面配置为指定webhttp响应格式为JSON格式:
<behaviors> <serviceBehaviors> <behavior> <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false --> <serviceMetadata httpGetEnabled="true"/> <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="web"> <webHttp defaultOutgoingResponseFormat="Json"/> </behavior> </endpointBehaviors> </behaviors>