2010-11-15 132 views
3

我無法找到此問題的答案。通過調整web.config文件中的一些最大大小設置,大多數類似的帖子精簡似乎已被修復。但是,這些建議都沒有解決我的問題。WCF錯誤 - 意外的響應:(400)錯誤的請求

爲了給出更多背景,我將一個asmx Web服務移植到Windows Azure中承載的WCF Web服務。測試期間出現這個問題。如果我在一次調用中將少量事務傳遞給我的web服務,它往往工作得很好。雖然我的交易規模大約在50-60(交易)時出現這個錯誤。序列化到XML,文件大小約爲300K,所以它沒有任何瘋狂的大。但它傾向於傾向於尺寸問題。

此外,接通WCF跟蹤,我發現下面的例外發生的歷史:

System.ServiceModel.ProtocolException:最大消息大小配額用於傳入消息(65536)已經被超過。要增加配額,請在適當的綁定元素上使用MaxReceivedMessageSize屬性。

在System.ServiceModel.Channels.HttpInput.ThrowHttpProtocolException(字符串消息,HttpStatusCode的StatusCode,字符串狀態說明)

在System.ServiceModel.Channels.HttpInput.ThrowMaxReceivedMessageSizeExceeded()

在System.ServiceModel.Channels .HttpInput.ReadBufferedMessage(流的inputStream)

在System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(例外&放大器;放大器; requestException)

在System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext背景下,操作回調)

從異常

所以,它看起來好像其中一個設置,如果關在我的web.config,但這裏是什麼看起來像:

<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    <behavior name="MetadataEnabled"> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceMetadata httpGetEnabled="true"/> 
     <useRequestHeadersForMetadataAddress> 
     <defaultPorts> 
      <add scheme="http" port="8081"/> 
      <add scheme="https" port="444"/> 
     </defaultPorts> 
     </useRequestHeadersForMetadataAddress> 
     <dataContractSerializer maxItemsInObjectGraph="111024000"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled"> 
    <endpoint name="HttpEndpoint" 
       address="" 
       binding="wsHttpBinding" 
       bindingConfiguration="wsHttp" 
       contract="Bandicoot.CORE.IRepricer" /> 
    <endpoint name="HttpMetadata" 
       address="contract" 
       binding="mexHttpBinding" 
       bindingConfiguration="mexBinding" 
       contract="Bandicoot.CORE.Stack" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/Core"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<bindings> 
    <wsHttpBinding> 
    <binding name="wsHttp" maxReceivedMessageSize="111024000" 
      messageEncoding="Text" maxBufferPoolSize="111024000" 
      textEncoding="UTF-8"> 
     <readerQuotas maxBytesPerRead="111024000" 
        maxArrayLength="111024000" 
        maxStringContentLength="111024000"/> 
     <security mode="None"/> 
    </binding> 
    </wsHttpBinding> 
    <mexHttpBinding> 
    <binding name="mexBinding"/> 
    </mexHttpBinding> 
</bindings> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

沒有人有任何其他建議,或者有在我的web.config,我只是沒有看到的東西誤配置的?

感謝您的任何建議!

編輯:這是我的客戶的app.config設置

<bindings> 
<basicHttpBinding> 
    <binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00" 
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="14194304" maxBufferPoolSize="14194304" maxReceivedMessageSize="14194304" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
      useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="1000" maxStringContentLength="111024000" 
      maxArrayLength="111024000" maxBytesPerRead="1024000" maxNameTableCharCount="111024000" /> 
     <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
</basicHttpBinding> 

編輯:添加另外的客戶信息:

 <client> 
     <endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE" 
      name="BasicHttpBinding_CORE" /> 
    </client> 

編輯:嘗試改變服務綁定到basicHttpBinding的 - 配置更改:

 <basicHttpBinding> 
    <binding name="basicHttp" maxReceivedMessageSize="111024000" 
      messageEncoding="Text" maxBufferPoolSize="111024000" 
      textEncoding="UTF-8"> 
     <readerQuotas maxArrayLength="111024000" maxBytesPerRead="111024000" maxStringContentLength="111024000"/> 
     <security mode="None" /> 
    </binding> 
    </basicHttpBinding> 

     <service name="Bandicoot.Core" behaviorConfiguration="MetadataEnabled"> 
    <endpoint binding="basicHttpBinding" 
       bindingConfiguration="basicHttp" 
       contract="Bandicoot.CORE.IRepricer" /> 
    <endpoint address="mex" 
       binding="mexHttpBinding" 
       bindingConfiguration="mexBinding" 
       contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/Core"/> 
     </baseAddresses> 
    </host> 
    </service> 

和客戶端的應用程序。配置以及供參考:

 <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_CORE" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="100000000" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
       <security mode="None"> 
        <transport clientCredentialType="None" proxyCredentialType="None" 
         realm="" /> 
        <message clientCredentialType="UserName" algorithmSuite="Default" /> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:92/CORE.svc" binding="basicHttpBinding" 
      bindingConfiguration="BasicHttpBinding_CORE" contract="Core.CORE" 
      name="BasicHttpBinding_CORE" /> 
    </client> 
+0

和使用**這些設置是你的客戶端終端實際上​​*? – 2010-11-15 19:46:03

+0

你的服務定義了'wsHttpBinding' - 你的客戶有'basicHttpBinding'設置.....是那些即使匹配了?此外 - 你沒有告訴我們的' ...'你的客戶的配置的部分 - 這將是最有趣的! – 2010-11-15 20:44:43

+0

@marc_s - 此客戶端配置的大部分只是由Visual Studio中的「添加服務引用」功能自動生成的。由於我們的客戶都將消耗該Web服務,這將是可取的,如果他們沒有需要破解了一個配置文件,我們的服務工作...這可能是在它自己的另外一個問題,所以現在我只是想獲得它工作。我已經發布了我的配置文件的客戶端部分。請讓我知道,如果你看到任何看起來不正確的東西。謝謝! – Brosto 2010-11-15 21:04:32

回答

1

今天早上我終於明白了這一點。問題在於我的服務沒有使用我認爲是的配置設置。原因?配置中的服務名稱必須是正在實施的服務的完全限定路徑。

我發現這個link有用計算出來。

我覺得我的服務沒有指向實際的端點有點奇怪,我想它只是使用一系列的默認值,如果你想有不同的東西,你可以在web.config中配置它們嗎?我認爲這解釋了爲什麼當我在客戶端中使用webservice而不是wsHttpBinding時,我得到了一個basicHttpBinding。

花了幾天的時間弄清楚,但是很有教育意義。感謝您的建議!

2

您需要在客戶端上要設置maxReceivedMessageSize(你在哪裏從服務返回的消息是進入) - 在其app.configweb.config

<system.serviceModel> 
<bindings> 
    <wsHttpBinding> 
    <binding name="wsHttp" maxReceivedMessageSize="111024000" 
      messageEncoding="Text" maxBufferPoolSize="111024000" 
      textEncoding="UTF-8"> 
     <readerQuotas maxBytesPerRead="111024000" 
        maxArrayLength="111024000" 
        maxStringContentLength="111024000"/> 
     <security mode="None"/> 
    </binding> 
    </wsHttpBinding> 
    <mexHttpBinding> 
    <binding name="mexBinding"/> 
    </mexHttpBinding> 
</bindings> 
<client name="whatever"> 
    <endpoint name="HttpEndpoint" 
     address="" 
     binding="wsHttpBinding" 
     bindingConfiguration="wsHttp" 
     contract="Bandicoot.CORE.IRepricer" /> 
</client> 
</system.serviceModel> 

maxReceivedMessageSize的默認值是64K,除非您更改它。

+0

對不起,我沒有包含我的客戶端配置,我也有這個設置。我用我的app.config設置更新了原始問題。 – Brosto 2010-11-15 19:18:26

+0

正如@marc_s指出的那樣,客戶端似乎沒有使用這些設置。錯誤消息清楚地表明,電流限制是64K。 – TMN 2010-11-15 20:36:15

+0

我使用客戶端配置更新了原始帖子。會喜歡一些額外的建議。 – Brosto 2010-11-16 15:32:28

1

我有同樣的錯誤,原因顯露是配置錯誤了。

但在這種情況下,我是,像marc_s已經發布,在服務器端maxReceivedMessageSize設置。該服務器仍在使用其默認配置,該配置低至64 kb。

可以明顯看出這是因爲現在的聲音,那麼久花了我找出的錯誤並不在我的(客戶端)的一面。

我希望這可以幫助別人。

0

嗨問題海報「Brosto」!

這補充你的11月17日在'10 15:29答案。

我們有一個「樂趣」,或者我應該說今天的「教育」生產部署測試問題,一天中大部分時間都需要解決,而且它實際上是由一次按鍵引起的。在Web Farm完全部署後,我們發現問題消失後,我們只確認問題的根源。

這是原因。當我們測試我們的生產部署,並針對「單臺服務器」做到通過改變我們的hosts文件,我們繞過負載均衡器,並調用單個服務器最終會在默認http端口!當我們測試對「負載均衡」,調用從負載平​​衡器單個服務器,最終會在負載平衡器定義的端口!

由於服務端點地址必須是「完全限定」,以使服務能夠找到服務的自定義綁定。在單一服務器上的配置文件必須改變,以反映「單服務器」與「負載平衡服務器」端點連接之間的差異,具體如下:

單服務器連接:

endpoint address="http://www.myserver.com:80/Services/MyService.svc" 

負載平衡服務器連接:

endpoint address="http://www.myserver.com:81/Services/MyService.svc" 

我的老闆早期正確診斷的核心問題,他說,服務器充當像自定義綁定被忽略並且正在使用默認值。 顯示出他的評論以上,其中你提到的「完全合格」的服務端點地址的要求後,他意識到,主機文件重定向是造成的,而不是我們的瀏覽器請求去了默認的端口80的單服務器,負載平衡端口81,這實際上改變了完全合格的服務端點地址,導致服務器忽略這些自定義綁定並恢復到默認設置。 請注意,它不會調用服務,它只會綁定自定義綁定失敗!

希望有人會記住這一點發布,下一次我們生產測試服務與自定義綁定:)