首页 新闻 会员 周边

调用wcf 基础连接已经关闭: 连接被意外关闭。

0
悬赏园豆:100 [已解决问题] 解决于 2011-11-14 09:45

服务端的代码

var roles = from re in db.Roles   select re;                

return roles.ToList();

调试的时候能进入服务端代码,并能查到正确数据返回,数据量才二条,返回的数据大小不会超过默认设置的大小的。

但是在客户端就会报出异常,调用wcf 基础连接已经关闭: 连接被意外关闭。

未处理 System.ServiceModel.CommunicationException  Message=基础连接已经关闭: 连接被意外关闭。  Source=mscorlib  StackTrace:    Server stack trace:        在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)       在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)       在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)       在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)       在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)       在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)       在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:        在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)       在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)       在 Ship.PurviewWCFService.IPurviewService.GetAllRole()       在 Ship.PurviewWCFService.PurviewServiceClient.GetAllRole() 位置 D:\WorkSpace\Shipmvc\Ship\Ship\Service References\PurviewWCFService\Reference.cs:行号 780       在 Ship.Purview.PurivewMain.BindRole() 位置 D:\WorkSpace\Shipmvc\Ship\Ship\Purview\PurivewMain.cs:行号 381       在 Ship.Purview.PurivewMain.角色管理ToolStripMenuItem_Click(Object sender, EventArgs e) 位置 D:\WorkSpace\Shipmvc\Ship\Ship\Purview\PurivewMain.cs:行号 423       在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)       在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)       在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)       在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)       在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)       在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)       在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)       在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)       在 System.Windows.Forms.Control.WndProc(Message& m)       在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)       在 System.Windows.Forms.ToolStrip.WndProc(Message& m)       在 System.Windows.Forms.MenuStrip.WndProc(Message& m)       在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)       在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)       在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)       在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)       在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)       在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)       在 System.Windows.Forms.Application.Run(Form mainForm)       在 Ship.Program.Main() 位置 D:\WorkSpace\Shipmvc\Ship\Ship\Program.cs:行号 19       在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)       在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)       在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)       在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       在 System.Threading.ThreadHelper.ThreadStart()  InnerException: System.Net.WebException       Message=基础连接已经关闭: 连接被意外关闭。       Source=System       StackTrace:            在 System.Net.HttpWebRequest.GetResponse()            在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)       InnerException: 

请教园子里的兄弟,帮忙提示一下

问题补充:

所查询的表和别的表有关联,刚才试了下,没有关联的表查询数据返回就不会出问题,

服务端代码:

try            

{                

var users = from us in db.Users select us;               

  List<Users> userlist = users.ToList();                                            return userlist;           

 }         

catch (Exception et)            {       

         if (et.InnerException is SqlException)                 

    throw new FaultException(string.Format("数据库异常{0}",                 et.InnerException.Message), new FaultCode("数据库操作"));                else                    

    throw new FaultException(string.Format("返回用户列表异常:      {0}",et.InnerException.Message),new FaultCode("返回用户列表"));            }

客户端调用代码

 List<Users> users = purviewClient.GetAllUsers();

是不是和返回类型有关,序列化问题??????????????

自信飞扬的主页 自信飞扬 | 初学一级 | 园豆:56
提问于:2011-06-24 18:43
< >
分享
最佳答案
0

客户端和服务器的数据契约引用不一致  而客户端又没有自动生成数据契约  

收获园豆:25
菜鸟老了 | 初学一级 |园豆:145 | 2011-09-03 08:52
其他回答(5)
0

帮你顶顶,怎么都木有人。。

收获园豆:25
Agile45 | 园豆:130 (初学一级) | 2011-06-25 10:07
谢谢!
支持(0) 反对(0) 自信飞扬 | 园豆:56 (初学一级) | 2011-06-25 16:00
0

是的,和序列化相关,你可以通过wcf诊断工具来查找关键错误信息,从服务器的跟踪信息中应该可以看到序列化失败的异常。

收获园豆:25
Launcher | 园豆:45045 (高人七级) | 2011-06-25 10:08
db.ObjectTrackingEnabled = false;
就可以了。
支持(0) 反对(0) 自信飞扬 | 园豆:56 (初学一级) | 2011-06-25 12:46
0

哥们  你的这个问题解决没 

虫虫飞520 | 园豆:202 (菜鸟二级) | 2013-07-04 11:07

你看上面我的回复

支持(0) 反对(0) 自信飞扬 | 园豆:56 (初学一级) | 2013-08-13 08:30
0

WCF 接口请求可以通 只是请求响应后出现这个问题,其它接口都可以请求通过;

错误信息: 


System.Net.WebException: 基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。
---> System.IO.IOException: 无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。
---> System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接。


在 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- 内部异常堆栈跟踪的结尾 ---
在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
在 System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
在 System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- 内部异常堆栈跟踪的结尾 ---
在 System.Net.HttpWebRequest.GetResponse()
在 EHR.Core.WebServer.Request(String url, String param) 位置 D:\WorkCode\Eureka.Hospital.Solutions.EHR\Src\Servers\6 Foundation\EHR.Core\WebServer.cs:行号 47
在 EHR.Core.WebServer.GetWebServiceDateTime[T](String functionName, Object param) 位置 D:\WorkCode\Eureka.Hospital.Solutions.EHR\Src\Servers\6 Foundation\EHR.Core\WebServer.cs:行号 153

  

心路独舞 | 园豆:199 (初学一级) | 2018-06-05 10:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册