开发者

I need help solving a rather weird error in a WCF service

开发者 https://www.devze.com 2022-12-24 04:53 出处:网络
I have a solution that contains three projects. A main project with my MVC app, a silverlight application and a (silverlight enabled) WCF service project.

I have a solution that contains three projects. A main project with my MVC app, a silverlight application and a (silverlight enabled) WCF service project.

In my silverlight project i have made a Service Reference to my WCF service. And i pretty much got that working.

In my WCF service i have a method that returns an Book object, which got some random fields like title, date etc. In the book class, i have a ICollection field that contains a list of events.

The book class is generated using entity framework 4.0, and Lazy Loading is enabled.

If i in my getBook(int id) method return a book with the events field not initialized, it works as a charm.

But if i initialize the field, i'm getting this 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 have a few ideas why that is happening, and while writing this i just got another one.

  1. The wcf service somehow threw away the reference to the event class. That would be very weird since i have a reference between my main mvc app (with the models) and my WCF service.

  2. Since i have enabled lazy loading in EF 4.0, i suspect that it may be the thing generating the error. But i'm not sure why that would be, because i'm not in any way accessing that field. I could understand that i may not be able to access the events field after i recive the object in my silverlight application since the connection between the book object and the entity framework is like broken.

Did i mention that Lazy Loading is enabled on my EF instance? And there is no inner exception in the thrown exception.

EDIT: This is (i think) the exception on the server.


The underlying connection was closed: The connection was closed unexpectedly.

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.RequestChannelBin开发者_如何学编程der.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.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 RemoteProvider.getTimeline(Int32 id) at RemoteProviderClient.getTimeline(Int32 id)

Inner Exception: 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)


Thanks in advance. Malte Baden Hansen


Without more information on your actual structure, I can only hazard a guess, but that guess is this:

ICollection

That's your problem. You can't pass interfaces over the WCF wire without a lot of internal wrangling; so much so that I prefer to just build non-functional transfer objects whose only job is to contain data.

Turn your ICollection into a List or an array, and you're probably going to be fine.

The problem comes when de-serializing the incoming data. The framework tries to instantiate an interface, which it can't do, so it barfs. There are attributes that allow you to map the interface to a concrete type which WCF can instantiate, but they're obscure and difficult (IMO) to use in a maintainable way.


This could be a Serialization problem.

It could be that ICollection cannot be serialized or the your events object is not marked as serializable. To fix it:

  • Use List instead of ICollection
  • marke event as serializable
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号