当前位置:  开发笔记 > 后端 > 正文

无法理解WCF错误消息,需要帮助

如何解决《无法理解WCF错误消息,需要帮助》经验,为你挑选了1个好方法。

我有一个简单的Web服务,允许应用程序查询我的CMDB.我遇到问题的函数使用一个小的结果集但是失败了一个较大的结果集,表明它是WCF服务配置中阻止它成功的东西.

我有一个简单的WinForms测试应用程序,其中包含对Web服务的服务引用和一个调用相关函数的函数.

较小的结果集返回~120KB的xml,失败的较大结果集约为2MB.我已经尝试增加maxReceivedMessageSize和maxStringContentLength的大小而没有成功.

我错过了一些配置吗?如果那是问题,我会期待更详细的错误消息.

提前致谢,

缺口


返回的错误是:

System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly. --->
System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.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)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at TestRig.CmdbDataService.ICmdbDataService.GetMonitors(String client)
   at TestRig.CmdbDataService.CmdbDataServiceClient.GetMonitors(String client) in C:\Documents and Settings\nfoster\My Documents\Visual Studio Projects\Virtual Operations Manuals\Trunk\src\TestRig\Service References\CmdbDataService\Reference.vb:line 1480
   at TestRig.Form1.btnGetServers_Click(Object sender, EventArgs e) in C:\Apps\Virtual Operations Manuals\Trunk\src\TestRig\Form1.vb:line 8

应用程序中的调用函数是:

Private Sub btnGetMonitors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetMonitors.Click
  txtResults.Text = String.Empty
  Dim proxy As CmdbDataService.CmdbDataServiceClient = Nothing
  Try
    proxy = New CmdbDataService.CmdbDataServiceClient("WSHttpBinding_ICmdbDataService")
    Dim monitors As TestRig.CmdbDataService.ConfigurationItems = proxy.GetMonitors(txtClientName.Text)
    proxy.Close()
    For Each monitor In monitors
      txtResults.Text &= monitor.Name & " (" & monitor.TypeName & ")" & vbCrLf
    Next
    txtResults.Text &= monitors.Count & " monitors returned"
  Catch ex As Exception
    If Not IsNothing(proxy) AndAlso proxy.State <> ServiceModel.CommunicationState.Closed Then proxy.Abort()
    txtResults.Text = ex.ToString
  Finally
    proxy = Nothing
  End Try
End Sub

在测试装备方面,app.config包含以下serviceModel:

  
    
      
    
    
    
      
        
          
        
      
    
    
      
        
          
        
      
    
  

在服务端,web.config是:

  
    
      
    
    
      
        
        
        
      
    
    
      
        
          
          
        
      
    
  

Nick.. 15

我的一位同事刚刚在这篇博文中指出了我的实际罪魁祸首是端点行为中的maxItemsInObjectGraph属性.

把它们搞砸已经解决了这个问题,我必须刚刚超过了默认阈值65536:D

很高兴看到错误消息指向正确的方向:(

干杯....

另外:您可能会收到此错误,因为您的某个Web方法正在使用非类的[DataContract]类.



1> Nick..:

我的一位同事刚刚在这篇博文中指出了我的实际罪魁祸首是端点行为中的maxItemsInObjectGraph属性.

把它们搞砸已经解决了这个问题,我必须刚刚超过了默认阈值65536:D

很高兴看到错误消息指向正确的方向:(

干杯....

另外:您可能会收到此错误,因为您的某个Web方法正在使用非类的[DataContract]类.

推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有