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

时间:2011-11-29 22:46:09

标签: silverlight wcf wcf-binding basichttpbinding

我在网上浏览过,这个问题的解决方案似乎都不适用于我。我有一个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名称值(我已经完成了两个)。

1 个答案:

答案 0 :(得分:0)

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

也可能有其他地方。