WCF 請求正文過長致使返回400錯誤解決方案

今天用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"
相關文章
相關標籤/搜索