2015-09-30 84 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) –

相关问题