2014-11-03 127 views
5

我有WCF服務,我有一個方法,當我想通過參數大字符串(超過1MB)(413)請求實體過大

我運行這個WCF和WCF測試客戶端,我改變配置如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IMyService" sendTimeout="00:05:00" 
        maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
         maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 

而當我嘗試調用此方法時,我仍然有413請求實體太大。

+3

你改變* *兩端?服務器和客戶端? – 2014-11-03 21:54:52

+1

我添加到客戶端: <綁定名稱= 「BasicHttpBinding_IMyService」 maxBufferPoolSize = 「2147483647」 maxReceivedMessageSize = 「2147483647」> 但我仍然得到同樣的錯誤 – Robert 2014-11-04 07:11:19

回答

4

正如Matt Burland所說,您需要配置服務端以及客戶端。詳情請參閱Configuring Services Using Configuration Files。該任務與您在電線的客戶端完成的任務沒有多大區別。這是上述文章的摘錄。

WCF使用.NET Framework的System.Configuration配置系統。在Visual Studio中配置服務時,請使用 Web.config文件或App.config文件指定設置。配置文件名稱的 選擇取決於您爲服務選擇的主機環境 。如果您使用IIS來託管 您的服務,請使用Web.config文件。如果您使用任何其他 託管環境,請使用App.config文件。

我建議不設一切int.MaxValue爲有MaxReceivedMessageSize設置爲2GB打開你到DOS(拒絕服務)攻擊等。所述MaxReceivedMessageSize屬性的備註部分甚至規定:

,可以在電線上,通過使用WSHttpBindingBase服務 要接收的消息的大小是由分配給每個消息的內存量 界定。限制消息大小的限制旨在限制暴露於拒絕服務(DoS)攻擊。

您可能只是試圖讓它在這一點上起作用,但遠離推薦這樣離開它。

4

我也遇到了同樣的問題並解決了這個問題。 工作代碼-

(413) Request Entity Too Large in WCF 請遵循app.config代碼。這是工作和使用這個我可以發送大文件

<bindings> 
    <webHttpBinding> 
     <binding name="myBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Streamed" > 
      <readerQuotas maxDepth="64" maxArrayLength="2147483647" maxStringContentLength="2147483647"/> 
     </binding> 
    </webHttpBinding> 
</bindings> 
<services> 
    <service behaviorConfiguration="ForecastREST_API.RESTServiceImplBehavior" name="ForecastREST_API.RestServiceImpl"> 
     <endpoint address="http://localhost:59624/RestServiceImpl.svc" binding="webHttpBinding" contract="ForecastREST_API.IRestServiceImpl" behaviorConfiguration="Web" bindingConfiguration="myBinding"> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 
<behaviors> 
    <endpointBehaviors> 
     <behavior name="Web"> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
      <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" /> 
      <dispatcherSynchronization asynchronousSendEnabled="true" /> 
     </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
     <behavior name="ForecastREST_API.RESTServiceImplBehavior"> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
    </serviceBehaviors> 
</behaviors> 
+0

鏈接只答案都望而卻步 – Eldho 2016-07-12 11:54:28

+0

@Eldho我已經添加了工作代碼也。 – 2016-07-12 12:07:39

+0

對不起,還有其他1個已經投票 – Eldho 2016-07-12 12:08:42