2012-01-06 58 views
1

我正在調用WCF服務的一種方法。該方法將圖像內的圖形傳遞給服務。帶有大量消息的WCF呼叫服務

所有來電拋出異常的說法:

The remote server returned an unexpected response: (400) Bad Request 

我已閱讀關於這個問題的帖子很多,他們大多建議提高maxReceivedMessageSize。我試圖修改這個和其他設置,但它不能解決問題。

最後我已經激活服務器跟蹤它說:

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. 

在我的配置文件中的值設置爲65536000.

我的配置文件:

<?xml version="1.0"?> 
<configuration> 
    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel.MessageLogging" switchValue="Verbose, ActivityTracing"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelMessageLoggingListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
     <source name="System.ServiceModel" switchValue="Verbose,ActivityTracing" 
     propagateActivity="false"> 
     <listeners> 
      <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
      <filter type="" /> 
      </add> 
      <add name="ServiceModelTraceListener"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add initializeData="C:\Trace\messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> 
     <filter type="" /> 
     </add> 
     <add initializeData="C:\Trace\tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
     name="ServiceModelTraceListener" traceOutputOptions="Timestamp"> 
     <filter type="" /> 
     </add> 
    </sharedListeners> 
    <trace autoflush="true" /> 
    </system.diagnostics> 
    <system.serviceModel> 
    <diagnostics wmiProviderEnabled="true"> 
     <messageLogging logEntireMessage="true" logMalformedMessages="true" 
     logMessagesAtTransportLevel="true" /> 
     <endToEndTracing propagateActivity="true" activityTracing="true" 
     messageFlowTracing="true" /> 
    </diagnostics> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="Beh"> 
      <dataContractSerializer maxItemsInObjectGraph="10000000"/> 
      <enableWebScript /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehavior"> 
      <serviceMetadata httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <webHttpBinding> 
     <binding name="WebBinding" closeTimeout="00:10:00" openTimeout="00:10:00" 
      sendTimeout="00:10:00" maxBufferSize="65536000" maxBufferPoolSize="524288000" 
      maxReceivedMessageSize="65536000"> 
      <readerQuotas maxDepth="500000000" maxStringContentLength="500000000" 
      maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000" /> 
      <security mode="Transport" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="ServiceBehavior" name="WcfService1.PleasureKraftService"> 
     <clear /> 
     <endpoint behaviorConfiguration="Beh" binding="webHttpBinding" 
      bindingConfiguration="WebBinding" name="Basic" contract="WcfService1.IMyService" 
      listenUriMode="Explicit"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpsBinding" contract="WcfService1.IMyService" /> 
     </service> 
    </services> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.web> 
    <compilation debug="false"/> 
<customErrors mode="Off"/> 
    </system.web> 
    <connectionStrings> 
    <add name="Ent" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxxxxx;Initial Catalog=Eu;User ID=xxxxx;Password=xxxxx;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/> 
    </connectionStrings> 
</configuration> 
+0

我不知道如何解決你最後的問題智者。我們在公司使用不同的綁定,並在我們的'httpTransport'上設置'max ... Size'屬性。我已經刪除了我的答案,因此您的問題會得到更多的關注,因爲沒有答案。 – dasblinkenlight 2012-01-06 18:48:38

+0

我認爲WCF不會因爲某種原因閱讀我的綁定配置,而是將默認的配置放置在它的位置。感謝您的嘗試。 – Jakub 2012-01-06 19:07:02

回答

2

你可能需要在客戶端和服務上定義MaxReceivedMessageSize屬性。

+0

我同意,我認爲客戶正在得到比預期更大的信息。 – 2012-01-09 13:30:28

+1

客戶端上的MaxReceivedMessageSize設置無關緊要,圖像從客戶端傳遞到服務器而不是其他方式。據我所知,如果您從服務器獲得大量響應,您需要在客戶端上調整此屬性的大小。 – Jakub 2012-01-09 16:45:37

+0

另外,爲了100%確定:客戶端上的設置是相同的,我沒有問題在客戶端上獲取完全相同的數據。 – Jakub 2012-01-09 16:54:03

0
  1. 增加消息的最大配額,可能超時也取決於消息的大小 - 你可以這樣聲明性地或以編程方式如下所示。

    BasicHttpBinding Binding = new BasicHttpBinding();

    Binding.ReceiveTimeout = new TimeSpan(???, 0, 0); 
    Binding.SendTimeout = new TimeSpan(???, 0, 0); 
    Binding.OpenTimeout = new TimeSpan(???, 0, 0); 
    Binding.CloseTimeout = new TimeSpan(???, 0, 0); 
    
    Binding.ReaderQuotas.MaxStringContentLength = ???; 
    Binding.ReaderQuotas.MaxArrayLength = ???; 
    Binding.ReaderQuotas.MaxBytesPerRead = ???; 
    Binding.ReaderQuotas.MaxNameTableCharCount = ???; 
    Binding.MaxReceivedMessageSize = ???; 
    Binding.MaxBufferPoolSize = ???; 
    
  2. 將您的有效載荷送入小塊

選項1:組塊的有效載荷自己

選項2:通道分塊 http://msdn.microsoft.com/en-us/library/aa717050(v=vs.110).aspx