-->

无法通过web.config中设置maxReceivedMessageSize(Unable to

2019-07-18 09:49发布

现在我已经调查了400 - 错误请求代码的最后两个小时。 很多sugestions的推移朝着确保bindingConfiguration属性设置是否正确,并在我的情况,它是。

现在,我需要你的帮助,破坏了大楼我在之前:-)

我运行一个WCF服务的REST类型(非常轻巧,使用这种资源的灵感: http://msdn.microsoft.com/en-us/magazine/dd315413.aspx )通过提供了(现在)接受一个的XmlElement(POX) POST动词。

我目前只使用招的要求制造商实现真正的客户端之前(因为这是混合环境)。

当我这样做对XML比65K小,它工作正常 - 更大,它抛出此异常:最大邮件大小配额传入消息(65536)已超出。 为了增加配额,请使用相应绑定元素上MaxReceivedMessageSize财产。

这里是我的web.config文件(我甚至包括为(绝望的时刻,客户端标签)!):

<system.web>
    <httpRuntime maxRequestLength="1500000" executionTimeout="180"/>
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <webHttpBinding>
        <binding name="WebHttpBinding" maxReceivedMessageSize="1500000" maxBufferPoolSize="1500000" maxBufferSize="1500000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="1500000" maxArrayLength="1500000" maxBytesPerRead="1500000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <client>
      <endpoint address="" binding="webHttpBinding" bindingConfiguration="WebHttpBinding" contract="Commerce.ICatalogue"/>
    </client>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Catalogue">
        <endpoint address="" 
                  behaviorConfiguration="RestFull" 
                  binding="webHttpBinding"
                  bindingConfiguration="WebHttpBinding" 
                  contract="Commerce.ICatalogue" />
        <!-- endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" / -->
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestFull">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

在此先感谢导致succesfull呼叫与> 65K XML ;-)任何帮助

Answer 1:

好吧,这个人真的令我很难解决,我将不遗余力别人。 面临的挑战是在事实上,我使用了<%@ ServiceHost Factory="System.ServiceModel.Activation.WebServiceHostFactory" Service="fullyQualifiedClassName" %> ,这是一个很好的和简单的工厂实现方法。

然而,这种方法有其弊端; 由于需要在web.config文件中没有的配置,通过设计WebServiceHostFactory类不永远从web.config文件中读取。 我知道; 我可以从该类继承,并做出相应的变化,因此它可能确实是从配置文件读取,但是这似乎有点超出范围。

我的解决办法是要回去落实WCF的更传统的方式; <%@ ServiceHost Service="fullyQualifiedClassName" CodeBehind="~/App_Code/Catalogue.cs" %> ,然后使用我的已配置的值在web.config文件。

这是我修改的web.config文件(相对于马多克斯头痛):

<system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="XmlMessageBinding" maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" maxBufferSize="5000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" />
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="fullyQualifiedClassName" behaviorConfiguration="DevelopmentBehavior">
        <endpoint name="REST" address="" binding="webHttpBinding" contract="fullyQualifiedInterfaceName" behaviorConfiguration="RestEndpointBehavior" bindingConfiguration="XmlMessageBinding" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="RestEndpointBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="DevelopmentBehavior">
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
        <behavior name="ProductionBehavior">
          <serviceDebug httpHelpPageEnabled="false" includeExceptionDetailInFaults="false"/>
          <serviceMetadata httpGetEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

这种变化的另一个好处是,你现在可以直接从.NET引用您的WCF休息服务; 这不能使用工厂模式,我的实的XmlElement的通过了解决方案来完成。

我希望这可以帮助其他有类似问题?



Answer 2:

我知道这是一个非常古老的问题,它已经有一个答案...

无论如何...

我做了什么来解决这个“问题”我创建了一个工厂从WebServiceHostFactory继承和创造从WebServiceHost继承自定义服务主机

而在主机I推翻这样的OnOpening方法

protected override void OnOpening()
        {
            base.OnOpening();

            foreach (var endpoint in Description.Endpoints)
            {
                var binding = endpoint.Binding as System.ServiceModel.Channels.CustomBinding;

                foreach (var element in binding.Elements)
                {
                    var httpElement = element as System.ServiceModel.Channels.HttpTransportBindingElement;
                    if (httpElement != null)
                    {
                        httpElement.MaxBufferSize = 2147483647;
                        httpElement.MaxReceivedMessageSize = 2147483647;
                    }
                }
            }

        }


Answer 3:

我觉得我有同样的问题,但是当我配置了,然后它的工作默认绑定的webHttp:

<bindings>
        <webHttpBinding>
            <binding maxReceivedMessageSize="2000000"
                      maxBufferSize="2000000">
                <readerQuotas maxStringContentLength="2000000"/>
            </binding>
        </webHttpBinding>
    </bindings>

注意:在绑定没有名字。



Answer 4:

这是一个博客条目,我写的是与绝对最小的WCF服务器和客户端部分重新产生此问题:

WCF -固定客户端的字符串长度例外

特别是,你可能需要自定义绑定配置。 再现至少这个样本可能会给您的具体情况的一些想法。



文章来源: Unable to set maxReceivedMessageSize through web.config