【问题标题】:Where to put MaxReceivedMessageSize property in WCF service's web.config file?在 WCF 服务的 web.config 文件中将 MaxReceivedMessageSize 属性放在哪里?
【发布时间】:2012-04-15 13:26:18
【问题描述】:

我需要更改我的web.config 文件并将MaxReceivedMessageSize 属性添加到 我的web.config - 但在哪里?

已超出传入邮件的最大邮件大小配额 (65536)。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

   <?xml version="1.0"?>
   <configuration>
      <system.web>
        <compilation debug="false"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /></assemblies></compilation>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>

【问题讨论】:

  • 通常在绑定元素上设置。尽管您的 web.config 没有显示任何 WCF 服务的迹象
  • @DmitriyReznik:很可能是带有方便的“默认”端点的 .NET 4 WCF 服务

标签: c# wcf


【解决方案1】:

您需要为要使用的绑定定义绑定配置,然后您需要定义服务(在服务器端)和客户端(在客户端)以使用该绑定和绑定配置:

<system.serviceModel>
   <bindings>
      <!-- pick whichever binding you want .... -->
      <basicHttpBinding>
         <!-- binding configuration with a name -->
         <binding name="ExtendedMaxSize"  
             maxBufferSize="999999" maxReceivedMessageSize="999999" />
      </basicHttpBinding>
  </bindings>
  <services>
    <service name="Yournamespace.YourServiceClass" behaviorConfiguration="...">
      <!-- define endpoint with your binding and the name of the binding configuration
           that you have defined just above -->
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="ExtendedMaxSize"  
                contract="Yournamespace.IYourServiceContract" />
    </service>
  </services>

【讨论】:

    【解决方案2】:

    帮助那些可能像我一样最终来到这里的人。 我还不能添加到上面的 cmets 中(通常有人在我遇到问题之前很久就已经有了答案),所以我必须添加一个答案。

    我有一个 MVC 4 应用程序,我怀疑上面的初始示例来自实际 WCF 服务项目的 web.config。其中一个 cmets 提到他们怀疑这是一个 MVC 4 应用程序和默认配置设置。

    但是你如何解决这个问题?从更多的研究来看,似乎实际上需要对客户端的 web.config 进行更改,换句话说,就是对 WCF 服务有 REFERENCE 的项目的 web 配置。您会发现在那里进行更改要容易得多。该版本的 web.config 实际上将类似于您正在寻找的内容。

    这对我来说很容易并解决了我的问题。

    【讨论】:

      【解决方案3】:
      1. 与通常声称的相反,无需在服务器上设置。
      2. 与 MSDN 所说的相反,仅对传输绑定元素设置限制是不够的。也需要设置绑定本身。 例如:

      var targetBinding = new BasicHttpsBinding();
      
      targetBinding.MaxReceivedMessageSize = MaxWcfMessageSize;
      targetBinding.MaxBufferPoolSize = MaxWcfMessageSize;
      targetBinding.MaxBufferSize = MaxWcfMessageSize;
      
      var targetBindingElements = targetBinding.CreateBindingElements();
      var httpsBindElement = targetBindingElements.Find<HttpsTransportBindingElement>();
      
      httpsBindElement.MaxReceivedMessageSize = MaxWcfMessageSize;
      httpsBindElement.MaxBufferPoolSize = MaxWcfMessageSize;
      httpsBindElement.MaxBufferSize = MaxWcfMessageSize;
      
      TextMessageEncodingBindingElement tmbebe = targetBindingElements.Find<TextMessageEncodingBindingElement>();
      tmbebe.ReaderQuotas.MaxArrayLength = MaxWcfMessageSize;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-07
        • 2013-05-24
        • 1970-01-01
        • 2011-02-21
        • 2011-04-03
        • 2016-10-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多