3

在我目前是有暴露它返回一個商業實體的陣列WCF服務工作的項目,讓我們把它發票:WCF響應 - 驗證錯誤

Invoice[] GetInvoicesByTypeAndTime(InvoiceType invoiceType, byte startHour, byte? endHour); 

的身份驗證機制使用是Windows身份驗證,WCF服務託管在託管在IIS 6上的Web應用程序中。

首先,當我用於獲取超過64kB的數據時,拋出CommunicationException,指出「傳入消息的最大消息大小配額(65536 )已超出。要增加配額,請使用適當的MaxReceivedMessageSize屬性綁定元素「。很好,我只是在App.config中將值增加到65536000(我最後在最後添加了三個零),這兩個值都是maxReceivedMessageSize和maxBufferSize(後者是因爲它在ArgumentException中抱怨「對於TransferMode.Buffered,MaxReceivedMessageSize和MaxBufferSize必須是相同的值。 參數名稱:bindingElement「)。

現在我能得到更大的反應......

直到我打了另一個極限(我認爲)後624元一個奇怪的異常被拋出(約2.2 MB):

System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. 
    at System.Net.HttpWebRequest.GetResponse() 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
    --- End of inner exception stack trace --- 

服務器堆棧跟蹤:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at Test2.DBS.IDbService.GetInvoicesByTypeAndTime(InvoiceType invoiceType, Byte startHour, Nullable`1 endHour) 
    at Test2.DBS.DbServiceClient.GetInvoicesByTypeAndTime(InvoiceType invoiceType, Byte startHour, Nullable`1 endHour) in D:\TEMP\Test2\Test2\Service References\DBS\Reference.cs:line 1445 
    at Test2.Program.Main(String[] args) in D:\TEMP\Test2\Test2\Program.cs:line 19 
:在[0]

at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory factory) 
    at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
    at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

異常重新拋出

驗證響應是否有限制? ASP.NET設置有沒有限制?

+0

感謝的Yannick M.重新格式化:) – 2010-01-13 09:54:21

回答

3

我猜你正在使用Windows身份驗證,因此是401而不是解釋你如何吹掉消息限制的消息。當您通過Windows Authenticated請求發送時,WCF會發送兩次SOAP請求,一次發送失敗並返回接受標頭,第二次用Windows Authentication標頭髮送它。

但是,從我的測試看來,如果郵件確實通過了,它仍然會失敗。

要解決這個問題,我不得不把服務器跟蹤日誌記錄中:

<system.diagnostics> 
    <trace autoflush="true" /> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Critical, Error, Warning"> 
     <listeners> 
      <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\Logs\ServiceTrace.svclog"/> 
     </listeners> 
     </source> 
    </sources> 
    </system.diagnostics> 

然後,我不得不把在較大的讀者配額,如上述(但我用更小的值):

那你一般都放在一個自定義的行爲,以增加對象圖的最大項目數:

<behaviors> 
    <serviceBehaviors> 
    <behavior name="MaximumItemsBehaviour"> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" /> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

您需要爲值爲「MaximumItemsBehaviour」的「<system.serviceModel><services><service>」元素添加「behaviourConfiguration」屬性。

其他建議我讀,但也沒必要自己是添加:

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <httpRuntime maxRequestLength="2097151" /> 
    </system.web> 

和:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <security> 
     <requestFiltering> 
     <requestLimits maxAllowedContentLength="209715200"/> 
     </requestFiltering> 
    </security> 
    </system.webServer> 
0

在客戶端看看readerQuotas,如果你想要TLDR版本 - 看看這是否確實是你的問題,你可以設置最大值(Int32.MaxValue),如下所示。

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
+1

感謝bnkdev指出這一點,嘗試過,但它不能解決它:( – 2010-01-14 07:38:05