今天用WCF作文章新增的时候,发现当POST请求正文超过必定字符数量(ContentLength > 1w)后服务器老是返回400错误,最后查明是因为WCF对请求正文长多作了限制,能够在配置文件中加入以下配置。web
<system.serviceModel> <services> <service behaviorConfiguration="webApi.AddBehavior" name="webApi.Add"> <host> <baseAddresses > <add baseAddress="http://localhost:8000/api/"></add> </baseAddresses> </host> <endpoint address="add" binding="webHttpBinding" bindingConfiguration="webBind" behaviorConfiguration="restful" contract="webApi.IAdd"></endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="webApi.AddBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="restful"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <bindings> <webHttpBinding> <binding name="webBind" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/> </binding> </webHttpBinding> </bindings> </system.serviceModel>
添加对绑定的配置,设定能够接受的正文的最大长度.api
<bindings> <webHttpBinding> <binding name="webBind" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/> </binding> </webHttpBinding> </bindings>
在终结点中添加绑定配置的name服务器
bindingConfiguration="webBind"