底层连接已关闭:连接意外关闭#2

时间:2012-08-10 13:09:05

标签: c# .net wcf web-services

在收到此错误之前,我做了修改。我已在所有班级中将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

2 个答案:

答案 0 :(得分:1)

由于对您要实现的目标缺乏解释,您是否更新了所有消费者以使用新类?我认为你已经改变了数据合同和这个破碎的消费者。

如果不是,我会查看您要传输的数据量,请参阅此blog post!似乎这是个问题。

我遇到了一些相同的问题,可能是配置问题,或者如果你在IIS中托管,这是一个关于权限的问题,请详细说明。

答案 1 :(得分:0)

如果您希望从被调用的方法返回并使用WCF服务,则此错误背后的一个可能原因可能是您的对象序列化/反序列化问题。如果您的服务方法返回的内容不是可序列化的,那么您的代理通道会发出此错误。

为避免这种情况,请检查 -

  1. 返回类型并确保它是可序列化的。您可能必须在类中添加[Serializable]属性。
  2. 拥有[DataMember(IsRequired=true)],它告诉序列化时该值将存在(它表示下划线属性是一种不可为空的值类型)。
  3. 确保您的枚举值与表中存储的值匹配。这是非常危急的情况,因为你不期望它。