簡體   English   中英

WCF服務錯誤413實體太大

[英]WCF Service Error 413 Entity Too Large

需要一些與WCF錯誤有關的信息,我正在了解請求實體太大(錯誤413)。

幾乎,該服務是一個簡單的[OperationContract],它接受字符串作為參數。

<IService.cs>
[OperationContract]
string UploadReportText(string ReportText);


<Service.cs>
public string UploadReportText(string ReportText)
{
  // Code to process data passed.
}

我已經為服務設置了Web配置,如下所示:

<bindings>
 <webHttpBinding>
    <binding maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
   </binding>
 </webHttpBinding>
</bindings>

盡管我相信IIS中的uploadReadAhead值無需更改(因為我未使用SSL),但我仍然對其進行了修改,使其值為2147483647。

跟蹤其中一個在Chrome中調用該服務的應用,我可以看到數據Content-Length為169786。

真的很困惑,在哪里可以找到與此相關的進一步信息。

贊賞任何見識。 謝謝

更新:附加信息如果我將傳遞給服務的字符串數據設置為較小的長度,則不會出錯。 我所做的大部分與此相關的搜索都指向maxReceivedMessageSize,需要將其調整為最大可能值,但是在Web配置中進行設置似乎無效。

更新:啟用日志記錄,我收到此消息:

異常詳細信息: System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. System.ServiceModel.ProtocolException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

首先:在服務器端,您定義了具有更大消息大小的綁定配置,但是沒有從端點引用它。

  <service behaviorConfiguration="WCFReferrals.Service1Behavior"
             name="WCFReferrals.Referrals">
       <endpoint 
             address="" 
             binding="wsHttpBinding" 
             bindingConfiguration="LargeSizeMessages"  <== you need to reference the binding config (by specifying its name
            contract="WCFReferrals.IReferrals">
        </endpoint>
        .....
      </service>
      ....
      <binding name="LargeSizeMessages"   <== give it a meaningful name
           maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
           <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
               maxArrayLength="2147483647" maxBytesPerRead="4096" 
               maxNameTableCharCount="16384" />
      </binding>

資源

也參考這個

還需要在客戶端執行相同的操作。 您的客戶端配置( app.config還包括大消息大小的綁定配置。

正如Vignesh所說,您沒有為定義的綁定分配名稱。 這使其成為該綁定的默認配置(在WCF 4.0及更高版本中),因此實際上有兩個選擇。 您可以給它命名,創建一個明確的端點,並根據Vignesh的建議通過bindingCongifuration對其進行引用。

或者,您可以使用<system.serviceModel>部分的<proctolMapping>部分來將webHttpBinding分配為http的默認綁定( http的常規WCF默認綁定為basicHttpBinding

<system.serviceModel>
  <protocolMapping>
    <add binding="webHttpBinding" scheme="http" />
  </protocoalMapping>
</system.serviceModel>

這放在服務的配置文件中。

對我來說,我只需要將此塊添加到我的web.config中

<bindings>
  <webHttpBinding>
    <binding maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647777" >
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />
    </binding>
  </webHttpBinding>
</bindings>

我的web.config已經使用了webHttpBinding綁定(如下所示),它只需要此<bindings>部分允許其上傳大文件。

<services>
    <service name="PocketCRMServices.Service1">
      <endpoint address="../Service1.svc"
        binding="webHttpBinding"
        contract="PocketCRMServices.IService1"
        behaviorConfiguration="webBehaviour" />
    </service>
</services>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM