在 web.config 中更改时,WCF MaxReceivedMessageSize 将不会更新

发布于 2024-12-18 11:01:31 字数 2361 浏览 1 评论 0原文

我在网上浏览了一下,这个问题的解决方案似乎都不适合我。我有一个由 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 或忘记为端点提供绑定配置名称值(这两者我都完成了)。

I've looked around on the web and none of the solutions to this problem seem to work for me. I have a WCF service being consumed by a Silverlight application. Everything works fine until I attempt to update a large object graph. My trace logs greet me with the lovely 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.

I've changed the setting in both my web.config file and in the Silverlight's ClientConfig file and even tried manually creating the proxy and setting the value in code.

My 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>

My 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);

Does anyone see what I've missed here? Everything I find on the web points out that someone forgot to either set maxReceivedMessageSize or forgot to give the endpoint a bindingConfiguration name value (both of which I've done).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2024-12-25 11:01:31

呃。我讨厌 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());
        }
}

并且可能还有其他地方。

Uggh. I hate this particular aspect of WCF. It's unnecessarily complex to understand, and hard to get right.

I don't claim to understand it all, but I know that there are other places where the "MaxReceivedMessageSize" property can be set, in addition to the binding proper. Also try the underlying transport, like so:

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

Or like this:

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());
        }
}

And there may be other places as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文