【问题标题】:WCF MaxReceivedMessageSize will not update when changed in the web.configWCF MaxReceivedMessageSize 在 web.config 中更改时不会更新
【发布时间】:2012-01-09 06:27:41
【问题描述】:

我在网上四处查看,但似乎没有一个解决这个问题的方法对我有用。我有一个被 Silverlight 应用程序使用的 WCF 服务。在我尝试更新大型对象图之前,一切正常。我的跟踪日志以可爱的错误迎接我:

传入邮件的最大邮件大小配额 (65536) 已达到 超过。要增加配额,请使用 MaxReceivedMessageSize 相应绑定元素上的属性。

我已经更改了 web.config 文件和 Silverlight 的 ClientConfig 文件中的设置,甚至尝试手动创建代理并在代码中设置值。

我的 web.config:

  <system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
      <endToEndTracing propagateActivity="true" activityTracing="true"
             messageFlowTracing="true" />
    </diagnostics>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingSettings" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" 
                 maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="TestConfigService">
        <endpoint address="" contract="PreferencesUI.Hub.PreferenceSVC.ITestConfig" binding="basicHttpBinding"
                  bindingConfiguration="basicHttpBindingSettings" />
      </service>
    </services>
  </system.serviceModel>

我的 Silverlight:

        EndpointAddress ea = new EndpointAddress("http://localhost:37935/TestConfig.svc");


        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
        binding.CloseTimeout = new TimeSpan(00, 5, 00);
        binding.OpenTimeout = new TimeSpan(00, 5, 00);
        binding.ReceiveTimeout = new TimeSpan(00, 5, 00);
        binding.SendTimeout = new TimeSpan(00, 5, 00);
        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.MaxReceivedMessageSize = int.MaxValue;
        binding.MaxBufferSize = int.MaxValue;


        _preferenceTSTServiceProxy = new TSTC.TestConfigClient(binding, ea);

有人看到我在这里错过了什么吗?我在网上找到的所有内容都指出有人忘记设置 maxReceivedMessageSize 或忘记为端点提供 bindingConfiguration 名称值(我都已完成)。

【问题讨论】:

    标签: silverlight wcf wcf-binding basichttpbinding


    【解决方案1】:

    哎呀。我讨厌 WCF 的这个特殊方面。理解起来非常复杂,而且很难正确理解。

    我并没有声称完全理解它,但我知道除了正确的绑定之外,还有其他地方可以设置“MaxReceivedMessageSize”属性。还可以尝试底层传输,如下所示:

        <binding name="CustomBinding_IRoomService">
          <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
        </binding>
    

    或者像这样:

    private void AddNetTcpEndpoint()
    {
        var binaryMessageEncodingTcp = new BinaryMessageEncodingBindingElement
        {
            MaxSessionSize = ushort.MaxValue
        };
        binaryMessageEncodingTcp.ReaderQuotas.MaxDepth = ushort.MaxValue;
        var tcpDuplexBinding = new CustomBinding(
            binaryMessageEncodingTcp,
            new TcpTransportBindingElement {MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue}
            );
        tcpDuplexBinding.SendTimeout = TimeSpan.FromMinutes(2);
        tcpDuplexBinding.ReceiveTimeout = TimeSpan.FromMinutes(30);
        tcpDuplexBinding.OpenTimeout = TimeSpan.FromSeconds(30);
        tcpDuplexBinding.CloseTimeout = TimeSpan.FromSeconds(30);
    
        AddServiceEndpoint(
            typeof (IRoomService),
            tcpDuplexBinding,
            "tcpDuplex").Behaviors.Add(new SilverlightFaultBehavior());
            }
    }
    

    而且可能还有其他地方。

    【讨论】:

    • basicHttpBinding 没有 httpProtocol 元素。将其更改为 customBinding 以访问该配置元素,但仍然没有骰子。不过感谢您的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-14
    • 2012-07-20
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多