2011-11-29 60 views
0

我在網上瀏覽過,沒有任何解決方案對這個問題似乎適用於我。我有一個Silverlight應用程序正在使用WCF服務。一切工作正常,直到我嘗試更新大對象圖。我跟蹤日誌迎接我可愛的錯誤:WCF MaxReceivedMessageSize在web.config中更改時不會更新

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.

我在我的兩個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名稱值(我已經完成了這兩個操作)。

回答

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

而且有可能是其他地方也是如此。

+0

basicHttpBinding沒有httpProtocol元素。將其更改爲customBinding以訪問該配置元素,但仍然沒有骰子。還是)感謝你的建議。 – user1072314

相關問題