2013-12-18 110 views
1

需要一些關於如何看待進一步相關的WCF錯誤我得到關於請求實體太大(錯誤413)。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的服務的應用程序的一個價值,我可以看到數據內容長度是169786.

真的難倒wher e看起來更進一步與此相關。

感謝任何見解。謝謝

更新: 附加信息 如果我將傳遞給服務的字符串數據設置爲更小的長度,我沒有收到錯誤。我所做的大部分搜索都與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.

回答

6

首先:在你的服務器端,你定義一個更大的郵件大小的綁定配置,但你不要從您的端點引用它。

<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> 

Source

Refer this too

+1

綁定配置=「LargeSizeMessages」的伎倆嘗試了許多解決方案 – smoothumut

0

還需要做同樣的事情在你的客戶端也是如此。您的客戶端配置(app.config也包含大消息大小的綁定配置)

+0

爲了簡單性和一致性,是後。但是,如果客戶沒有收到大量的回覆,那麼從技術上講,較大的值不需要設置。 – Tim

0

正如Vignesh所說,您沒有爲您定義的綁定分配名稱,這使得它成爲該綁定的默認配置(在WCF 4.0+版本),所以你實際上有兩個選擇:你可以給它一個名稱,創建一個明確的終點,並通過bindingCongifuration引用它,每維涅什的建議。

或者,你可以使用<system.serviceModel>部分的<proctolMapping>部分指定webHttpBinding作爲http的默認綁定(http的常規WCF默認綁定爲basicHttpBinding

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

這發生在您的服務的配置文件中。

0

對我來說,我只是需要將這個塊添加到我的網頁。配置

<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> 
相關問題