如何提高MaxReceivedMessageSize调用从C#中的WCF时 [英] how to increase MaxReceivedMessageSize when calling a WCF from C#

查看:205
本文介绍了如何提高MaxReceivedMessageSize调用从C#中的WCF时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/5459697/the-maximum-message-size-quota-for-incoming-messages-65536-has-been-exceeded\">The最大邮件大小配额传入消息(65536)已超过

我使用的文件上传和下载WCF。上传成功,但是当我下载一个大文件,我发现这个错误

I am using WCF for file uploading and downloading. uploading is successful but when i downloading a large file i found this error

错误:最大邮件大小配额传入消息(65536)
  已超出。为了增加配额,使用
  相应的绑定元素上MaxReceivedMessageSize属性。

Error : 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.

我Service.config文件具有以下code。

My Service.config file has the following code.

<system.web>
    <compilation debug="true" />
    <httpRuntime executionTimeout="4800" maxRequestLength="2147483647" />


  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"  />
        </binding>
      </basicHttpBinding>
      <!--<webHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </webHttpBinding>-->
    </bindings>
    <services>
      <service name="WITSService.WITSService">
        <clear />
        <endpoint binding="basicHttpBinding" contract="WITSService.WITSService" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="myEndPointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

任何一个可以帮助我如何提高MaxReceivedMessageSize

can any one help me how to increase MaxReceivedMessageSize

推荐答案

更改customBinding在web.config使用较大的默认值。我拿起2MB,因为它是一个合理的规模。当然,它设置为2GB(如下),将工作,但它确实让你更容易受到攻击。选择一个大小比你最大的要求较大,但并不过分大。

Change the customBinding in the web.config to use larger defaults. I picked 2MB as it is a reasonable size. Of course setting it to 2GB (as below) will work but it does leave you more vulnerable to attacks. Pick a size that is larger than your largest request but isn't overly large.

检查:使用Silverlight中的大消息请求与WCF

<system.serviceModel>
   <behaviors>
     <serviceBehaviors>
       <behavior name="TestLargeWCF.Web.MyServiceBehavior">
         <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="false"/>
       </behavior>
     </serviceBehaviors>
   </behaviors>
   <bindings>
     <customBinding>
       <binding name="customBinding0">
         <binaryMessageEncoding />
         <!-- Start change -->
         <httpTransport maxReceivedMessageSize="2097152"
                        maxBufferSize="2097152"
                        maxBufferPoolSize="2097152"/>
         <!-- Stop change -->
       </binding>
     </customBinding>
   </bindings>
   <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
   <services>
     <service behaviorConfiguration="Web.MyServiceBehavior"             name="TestLargeWCF.Web.MyService">
       <endpoint address=""
                binding="customBinding"
                bindingConfiguration="customBinding0"
                contract="TestLargeWCF.Web.MyService"/>
       <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange"/>
     </service>
   </services>
 </system.serviceModel> 

这篇关于如何提高MaxReceivedMessageSize调用从C#中的WCF时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆