簡體   English   中英

(413請求實體太大

[英](413) Request Entity Too Large

我有WCF服務,當我想將參數作為大字符串傳遞時,我有一個方法(超過1mb)

我運行此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個請求實體太大了。

正如Matt Burland建議的那樣,您需要配置服務端以及客戶端。 有關詳細信息,請參閱使用配置文件配置 這項任務與您在電線的客戶端所做的工作沒有太大的不同。 這是上述文章的摘錄。

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

我建議不要將所有內容設置為int.MaxValue因為將MaxReceivedMessageSize設置為2GB會打開DOS(拒絕服務)攻擊等。 MaxReceivedMessageSize屬性的備注部分甚至指出:

使用WSHttpBindingBase的服務可以在線路上接收的消息的大小受到為每條消息分配的內存量的限制。 這種對郵件大小的約束旨在限制拒絕服務(DoS)攻擊的風險。

你可能只是想讓它在這一點上起作用,但是建議不要這樣做。

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

(413)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>

這適用於我,在web.config應用程序端:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IXXXXXX" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
</system.serviceModel>

在web.config服務端,您需要在下一個標簽中添加此代碼:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IXXXXXX" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings> 
    <services>
      <service name="ServiciosSoporteVital.WCFCaso">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_IXXXXXX"
                  contract="ServiciosSoporteVital.IWCFCaso"/>
      </service>
    </services>     
</system.serviceModel>

最重要的是兩個應用程序中通過綁定名稱和bindingConfiguration的關系。

暫無
暫無

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

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