2015-09-30 83 views
8

我已經使用WCF實現了一小部分REST服務。其中一項服務收到大量數據。當調用它(這是從Visual Studio運行過程中出現的時候了 - 我還沒有部署國際熱帶木材組織生產服務器還)我得到的錯誤WCF服務返回的意外響應:(413)請求實體太大

The remote server returned an error: (413) Request Entity Too Large.

我的web配置

<binding name="BasicHttpBinding_ISalesOrderDataService" 
     closeTimeout="00:10:00" 
     openTimeout="00:10:00" 
     receiveTimeout="00:10:00" 
     sendTimeout="00:10:00" 
     allowCookies="false" 
     bypassProxyOnLocal="false" 
     hostNameComparisonMode="StrongWildcard" 
     maxBufferPoolSize="2147483647" 
     maxBufferSize="2147483647" 
     maxReceivedMessageSize="2147483647" 
     textEncoding="utf-8" 
     transferMode="Buffered" 
     useDefaultWebProxy="true" 
     messageEncoding="Text"> 
    <readerQuotas maxDepth="2000000" 
       maxStringContentLength="2147483647" 
       maxArrayLength="2147483647" 
       maxBytesPerRead="2147483647" 
       maxNameTableCharCount="2147483647" /> 
    <security mode="None"> 
    <transport clientCredentialType="None" 
       proxyCredentialType="None" 
       realm="" /> 
    <message clientCredentialType="UserName" 
      algorithmSuite="Default" /> 
    </security> 
</binding> 
+0

你在哪裏託管?在IIS中? –

+0

是在IIS ..。 – Rakin

+0

我的數據只有20KB。當我將對象轉換爲JSON。 – Rakin

回答

3

另外以同樣的方式要增加消息大小和緩衝區大小引用,請考慮爲序列化程序增加maxItemsInObjectGraph。如果你的對象內部有複雜的結構或者對象數組,那麼這很重要。 我們的典型設置看起來很

<behaviors> 
    <endpointBehaviors> 
    <behavior name="GlobalEndpoint"> 
     <dataContractSerializer maxItemsInObjectGraph="1365536" /> 
    </behavior> 
</behaviors> 
<serviceBehaviors> 
    <behavior name="GlobalBehavior"> 
     <dataContractSerializer maxItemsInObjectGraph="1365536" /> 
    </behavior> 
</serviceBehaviors> 

而且additionaly什麼Zwan提出

+0

我仍然有同樣的錯誤。 – Rakin

+0

這改善了很多....所以我把這個標記爲正確答案。 – Rakin

4

好像你超過配額擴充那些價值。

maxReceivedMessageSize="2000000" maxBufferSize="2000000"> 

(或查看您的查詢的結果較低時可能)

,如果沒有工作,檢查這裏它像COMON probleme。

The remote server returned an error: (413) Request Entity Too Large

+0

早些時候我用2000000 ..改成2147483647當我看到一些與此有關的文章 – Rakin

3

恐怕你的客戶是好的,但你需要檢查服務器的web.config

附加價值你爲你的客戶

<bindings> 
     <basicHttpBinding> 
     <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"> 
      <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     </binding> 
     </basicHttpBinding> 
</bindings> 
2

如果我理解正確,你的要求是提供大量數據的一個。這意味着你必須編輯@Zwan寫的maxRecievedMessageSize。不是在客戶端的配置中,而是在其餘的服務配置中,以允許大量的數據請求。

+0

如果我有名譽,我會把它寫成評論,但不幸的是我還沒有被允許這樣做。 –

1

如果您將wcf rest服務託管在asp.net應用程序中,則還必須設置httpRuntime限制,因爲wcf服務正在ASP .NET兼容性模式下運行。需要注意的是的maxRequestLength在千字節

的服務

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = 2147483647)] 
[GlobalErrorBehaviorAttribute(typeof(GlobalErrorHandler))] 
public partial class YourService : IYourService 
{ 

    // Flag: Has Dispose already been called? 
    bool disposed = false; 
    // Instantiate a SafeHandle instance. 
    SafeHandle handle = new SafeFileHandle(IntPtr.Zero, true); 

    // Public implementation of Dispose pattern callable by consumers. 
    public void Dispose() 
    { 
     Dispose(true); 
     GC.SuppressFinalize(this); 
    } 

    // Protected implementation of Dispose pattern. 
    protected virtual void Dispose(bool disposing) 
    { 
     if (disposed) 
      return; 

     if (disposing) 
     { 
      handle.Dispose(); 
      // Free any other managed objects here. 
      // 
     } 

     // Free any unmanaged objects here. 
     // 
     disposed = true; 
    } 

    ~YourService() // destructor 
    { 
     Dispose(); 
    } 

}

希望它可以幫助值

<configuration> <system.web> 
<httpRuntime maxRequestLength="10240" /> </system.web> </configuration> 

參考在The remote server returned an error: (413) Request Entity Too Large

更多的建議應作出處置,析構函數!

+0

<的httpRuntime executionTimeout = 「1200」 的maxRequestLength = 「1024000」 appRequestQueueLimit = 「300」/> – Rakin

+0

服務器settingd <的httpRuntime executionTimeout = 「200000」 的maxRequestLength = 「2147483647」/> – Rakin

+0

更多建議應使處置,析構函數的服務。看到我的答案。 –

1

由於確定與maxRecievedMessageSize,你可以檢查「IIS請求篩選」 的請求的內容,其中最大長度,以字節爲單位

在IIS

而且 - 「應將UploadReadAheadSize」阻止上傳和下載數據大於49KB。默認值是49152字節,可以增加到4 GB。

2

嘗試在web.config文件中增加「maxItemsInObjectGraph」大小,因爲此更改適用於我。有關詳細信息,請參閱。

+2

有關詳細信息,請參閱(https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.maxitemsinobjectgraph(v = vs.110).aspx) –

相關問題