【问题标题】:The underlying connection was closed: The connection was closed unexpectedly #2底层连接已关闭:连接意外关闭 #2
【发布时间】:2012-08-10 13:09:05
【问题描述】:

我在收到此错误之前所做的修改。我在所有课程中都将byte[] 更改为Stream

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.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 MyWCFServiceTest.MyWCFService.ICommonService.UploadDocument(UploadDocumentRequest request)    
   at MyWCFServiceTest.MyWCFService.MyServiceClient.MyWCFServiceTest.MyWCFService.ICommonService.UploadDocument(UploadDocumentRequest request) in C:\Users\KishoreJangid\Desktop\ChangeSAPTransactionStatus\MyWCFServiceTest - Copy\MyWCFServiceTest\Service References\MyWCFService\Reference.cs:line 2376    
   at MyWCFServiceTest.MyWCFService.MyServiceClient.UploadDocument(RequestHeader UploadDocumentReqHdr, Byte[]& UploadDocumentContent) in C:\Users\KishoreJangid\Desktop\ChangeSAPTransactionStatus\MyWCFServiceTest - Copy\MyWCFServiceTest\Service References\MyWCFService\Reference.cs:line 2383    
   at MyWCFService.Form1.DocumentUpload_Click(Object sender, EventArgs e) in C:\Users\KishoreJangid\Desktop\ChangeSAPTransactionStatus\MyWCFServiceTest - Copy\MyWCFServiceTest\Form1.cs:line 88

【问题讨论】:

  • 在 *.config 中为失败的端点启用 WCF 跟踪...您可能会得到更详细的异常。您发布的异常是通用/无用的。

标签: c# .net wcf web-services


【解决方案1】:

由于没有给出您想要达到的目标的解释,您是否已更新所有消费者以使用新类?我想你已经改变了数据合同和这个破碎的消费者。

如果不是,我会看看你传输了多少数据,请参考这个blog post!似乎这就是问题所在。

我也遇到了一些问题,可能是配置问题,或者如果您在 IIS 中托管,则存在有关权限的问题,请尽可能详细说明。

【讨论】:

    【解决方案2】:

    如果您期望从调用的方法返回并使用 WCF 服务,那么此错误背后的一个可能原因可能是您的对象序列化/反序列化问题。如果你的服务方法返回的东西不能序列化,那么你的代理通道就会出现这个错误。

    为避免这种情况,只需检查-

    1. 返回类型并确保它是可序列化的。您可能必须将 [Serializable] 属性与您的类一起放置。
    2. [DataMember(IsRequired=true)],它表示该值将在序列化时出现(其表示下划线属性是不可为空的值类型)。
    3. 确保您的枚举值与存储在表中的值相匹配。这是非常危急的情况,因为您没有预料到。

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多