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