使用 Linq“包含”时出错实体框架 4.1 的方法,Bug?
我使用 SQL Azure 作为数据库,采用实体框架 4.1 的代码优先技术。我从 WCF 作为中间层访问 EF,并提供对 ASP.NET MVC 3 的服务引用。EF
中的关系场景是 A->B->C
所以像往常一样我尝试获得 A 包括 B 包括 C 的可能性很小:
db.A.Include("B").Include("B.C")
db.A.Include("B").Include("C")
但在服务本身运行完美。由于添加了对 Web 应用程序的引用,它会尝试序列化并引发以下异常。我尝试进行真假延迟加载也没有成功。
"The underlying connection was closed: The connection was closed unexpectedly"
Stack Trace found:
at System.Net.HttpWebRequest.GetResponse() at
System.ServiceModel.Channels.HttpChannelFactory.
HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
我访问了 此页面 进行解析,并在中添加了建议的属性网络配置。现在我突然收到错误:
服务器没有提供有意义的回复;这可能是由于 合同不匹配、会话过早关闭或内部 服务器错误
我认为这可能是客户端和服务 web.configs 中某些标签/属性不匹配的问题,但一切都在那里。我无法通过加载整个集合属性来传递对象列表,从 wcf 服务到 Web 应用程序,我发现一件事非常繁重且性能低下。仍然面临上述问题,以在上述架构中获取 Web 应用程序的加载列表。有人可以帮忙吗......
I am using SQL Azure as database with code first technique of Entity framework 4.1. I'm accessing EF from WCF as middle tier and providing the service reference to ASP.NET MVC 3.
The relational scenario in EF is A->B->C
so as usual I tried to get A including B including C with few possibilities:
db.A.Include("B").Include("B.C")
db.A.Include("B").Include("C")
But in the Service itself running perfect. Since adding the reference to the web application it attempts to serialize and throws the exception below. I tried to make true-false lazy loading also without success.
"The underlying connection was closed: The connection was closed unexpectedly"
Stack Trace found:
at System.Net.HttpWebRequest.GetResponse() at
System.ServiceModel.Channels.HttpChannelFactory.
HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
I visited this page to resolve, and added the suggested attributes in web.config. Now I'm suddenly getting error:
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
I thought it might be issue of some tag/atrribute mismatch in client and service web.configs but everything is right there. One thing I could not get to passing the List of objects with loading of its entire cllection properties, from wcf service to web application is found very heavy and low in performance. still facing the above issues to get the loaded list at web application in above explained architecture. can some body help here....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嘿,谢谢柯克·布罗德赫斯特
,通过这个我可以跟踪问题。并在其周围进行搜索。我得到了解决方案。我在我的项目中添加了此类
,并且仅添加了:
[ReferencePreservingDataContractFormat]
作为属性,其中包含我想使用“包含”的方法定义。这对我有用。这可能对其他有需要的人有帮助。
hey Thanks Kirk Broadhurst
, By this I could track the Issue. and searche around it. I got the solution. I added this class in my project
And Added just :
[ReferencePreservingDataContractFormat]
as an attribute with the method definition where i wanted to use the "Include". thats it worked for me.This might be helpful for other needy people.
这是一个非常常见的 WCF 异常,可以是多种情况。 StackOverflow 上有数百个关于此问题的点击。
https://stackoverflow.com/search?q=%22The+underlying+connection+ was+close%22
您是 WCF 新手吗?任何服务电话都有效吗?这可能是简单的事情,例如超出了 maxMessageSize。
我建议您在服务上实现日志记录 - 在配置文件中添加一些诊断标签。
This is a very common WCF exception and can be any number of things. There are hundreds of hits on StackOverflow for this problem.
https://stackoverflow.com/search?q=%22The+underlying+connection+was+closed%22
Are you new to WCF? Do any service calls work? It could be something as simple as maxMessageSize exceeded.
I'd suggest you implement logging on your service - add some diagnostics tags to your configuration file.