【发布时间】:2011-02-01 18:56:49
【问题描述】:
我有一个包含三个项目的解决方案。 我的 MVC 应用程序、silverlight 应用程序和(启用了silverlight 的)WCF 服务项目的主项目。
在我的 silverlight 项目中,我对我的 WCF 服务进行了服务引用。 我几乎可以正常工作。
在我的 WCF 服务中,我有一个返回 Book 对象的方法,它有一些随机字段,如标题、日期等。 在 book 类中,我有一个包含事件列表的 ICollection 字段。
书类使用实体框架4.0生成,开启延迟加载。
如果我在我的 getBook(int id) 方法中返回一本未初始化事件字段的书,它就像一个魅力。
但如果我初始化该字段,我会收到此错误。
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
我对为什么会发生这种情况有一些想法,而在写这篇文章时,我又想到了一个。
wcf 服务以某种方式丢弃了对事件类的引用。 这会很奇怪,因为我在我的主 mvc 应用程序(带有模型)和我的 WCF 服务之间有一个引用。
由于我在 EF 4.0 中启用了延迟加载,我怀疑它可能是产生错误的原因。 但我不确定为什么会这样,因为我没有以任何方式访问该字段。我可以理解,在我的 silverlight 应用程序中接收对象后,我可能无法访问 events 字段,因为 book 对象和实体框架之间的连接就像断开了一样。
我是否提到在我的 EF 实例上启用了延迟加载? 并且抛出的异常没有内部异常。
编辑: 这是(我认为)服务器上的例外。
底层连接已关闭:连接意外关闭。
服务器堆栈跟踪: 在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest 请求,HttpAbortReason abortReason) 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时) 在 System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时) 在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,ProxyOperationRuntime 操作) 在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)
在 [0] 处重新抛出异常: 在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) 在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 类型) 在 RemoteProvider.getTimeline(Int32 id) 在 RemoteProviderClient.getTimeline(Int32 id)
内部异常: 基础连接已关闭:连接意外关闭。 在 System.Net.HttpWebRequest.GetResponse() 在 System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan 超时)
提前致谢。 马耳他巴登汉森
【问题讨论】:
-
请提供服务代码。您需要检查 server 上发生的异常,当您看到此情况时查看 client 异常无济于事。
-
在 vs 中调试时,我只收到上述异常。我不太确定如何访问服务器上发生的异常。
标签: .net asp.net-mvc wcf entity-framework exception