问题描述
建立了一些实体对象,封装好了业务逻辑,并将其发布为WCF服务,如果将其在代码中启动服务,编写测试用例测试,就会报:Test'WCFdb.WCFTest.TestUserInfoSVC.TestSaveUser'failed:System.ServiceModel.CommunicationException:接收对http://localhost:2251/UserService.svc的HTTP响应时发生错误。这可能是由于服务终结点绑定未使用HTTP协议造成的。这还可能是由于服务器中止了HTTP请求上下文(可能由于服务关闭)所致。有关详细信息,请参阅服务器日志。---->System.Net.WebException:基础连接已经关闭:接收时发生错误。---->System.IO.IOException:无法从传输连接中读取数据:远程主机强迫关闭了一个现有的连接。。---->System.Net.Sockets.SocketException:远程主机强迫关闭了一个现有的连接。Serverstacktrace:在System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebExceptionwebException,HttpWebRequestrequest,HttpAbortReasonabortReason)在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpantimeout)在System.ServiceModel.Channels.RequestChannel.Request(Messagemessage,TimeSpantimeout)在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Messagemessage,TimeSpantimeout)在System.ServiceModel.Channels.ServiceChannel.Call(Stringaction,Booleanoneway,ProxyOperationRuntimeoperation,Object[]ins,Object[]outs,TimeSpantimeout)在System.ServiceModel.Channels.ServiceChannel.Call(Stringaction,Booleanoneway,ProxyOperationRuntimeoperation,Object[]ins,Object[]outs)在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessagemethodCall,ProxyOperationRuntimeoperation)在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessagemessage)Exceptionrethrownat[0]:在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessagereqMsg,IMessageretMsg)在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32type)在WCFdb.WCFTest.ServiceReference1.IUserService.SaveUser(UserInfouser)ServiceReferencesServiceReference1Reference.cs(148,0):在WCFdb.WCFTest.ServiceReference1.UserServiceClient.SaveUser(UserInfouser)E:ProgramFilesvsworkspaceWCFDbStoreServiceWCFdb.WCFTestTestUserInfoSVC.cs(25,0):在WCFdb.WCFTest.TestUserInfoSVC.TestSaveUser()--WebException在System.Net.HttpWebRequest.GetResponse()在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpantimeout)--IOException在System.Net.Sockets.NetworkStream.Read(Byte[]buffer,Int32offset,Int32size)在System.Net.PooledStream.Read(Byte[]buffer,Int32offset,Int32size)在System.Net.Connection.SyncRead(HttpWebRequestrequest,BooleanuserRetrievedStream,BooleanprobeRead)--SocketException在System.Net.Sockets.Socket.Receive(Byte[]buffer,Int32offset,Int32size,SocketFlagssocketFlags)在System.Net.Sockets.NetworkStream.Read(Byte[]buffer,Int32offset,Int32size)
如果将其部署到IIS服务器,用相同的测试代码,报错:Test'WCFdb.WCFTest.TestUserInfoSVC.TestSaveUser'failed:System.ServiceModel.ProtocolException:响应消息的内容类型text/html;charset=utf-8与绑定(text/xml;charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。响应的前804个字节为:“<?xmlversion="1.0"?><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>服务器不可用</title></head><body><h1><spanstyle="font-family:Verdana;color:#ff3300">服务器应用程序不可用</span></h1><p><spanstyle="font-family:Verdana;">您试图在此Web服务器上访问的Web应用程序当前不可用。请点击Web浏览器中的“刷新”按钮重试您的请求。</span></p><p><b>管理员注意事项:</b>详述此特定请求失败原因的错误消息可在Web服务器的系统事件日志中找到。请检查此日志项以查明导致该错误发生的原因。</p></body></html>”。---->System.Net.WebException:远程服务器返回错误:(500)内部服务器错误。Serverstacktrace:在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequestrequest,HttpWebResponseresponse,HttpChannelFactoryfactory,WebExceptionresponseException)在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpantimeout)在System.ServiceModel.Channels.RequestChannel.Request(Messagemessage,TimeSpantimeout)在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Messagemessage,TimeSpantimeout)在System.ServiceModel.Channels.ServiceChannel.Call(Stringaction,Booleanoneway,ProxyOperationRuntimeoperation,Object[]ins,Object[]outs,TimeSpantimeout)在System.ServiceModel.Channels.ServiceChannel.Call(Stringaction,Booleanoneway,ProxyOperationRuntimeoperation,Object[]ins,Object[]outs)在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessagemethodCall,ProxyOperationRuntimeoperation)在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessagemessage)Exceptionrethrownat[0]:在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessagereqMsg,IMessageretMsg)在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32type)在WCFdb.WCFTest.UserInfoSvc.IUserService.SaveUser(UserInfouser)ServiceReferencesUserInfoSvcReference.cs(148,0):在WCFdb.WCFTest.UserInfoSvc.UserServiceClient.SaveUser(UserInfouser)E:ProgramFilesvsworkspaceWCFDbStoreServiceWCFdb.WCFTestTestUserInfoSVC.cs(25,0):在WCFdb.WCFTest.TestUserInfoSVC.TestSaveUser()--WebException在System.Net.HttpWebRequest.GetResponse()在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpantimeout)0passed,1failed,0skipped,took6.47seconds(NUnit2.5.5).
请问高手这是什么原因多谢了
解决方案
解决方案二:
有人知道原因吗
解决方案三:
找到原因了吗?求解答呀。。。
解决方案四:
懒加载问题,我在搭建这个框架时,遇到过,禁止懒加载
解决方案五:
请问如何解决的,我设置了懒加载还是不行的。
解决方案六:
WCF出现这种错误,基本都是因为服务端处理请求的时候,出现了错误。而你又没有启用输出错误。这时候,处理程序会直接关闭连接。调试一下,你的代码,不就知道什么原因了吗???