Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex data types in WCF?

I've run into a problem trying to return an object that holds a collection of childobjects that again can hold a collection of grandchild objects. I get an error, 'connection forcibly closed by host'.

Is there any way to make this work? I currently have a structure resembling this:

pseudo code:

Person:
IEnumerable<Order>

Order:
IEnumerable<OrderLine>

All three objects have the DataContract attribute and all public properties i want exposed (including the IEnumerable's) have the DataMember attribute.

I have multiple OperationContract's on my service and all the methods returning a single object OR an IEnumerable of an object works perfectly. It's only when i try to nest IEnumerable that it turns bad. Also in my client service reference i picked the generic list as my collection type. I just want to emphasize, only one of my operations/methods fail with this error - the rest of them work perfectly.

EDIT (more detailed error description):

[SocketException (0x2746): An existing connection was forcibly closed by
the remote host]
[IOException: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host.]
[WebException: The underlying connection was closed: An unexpected
error occurred on a receive.]
[CommunicationException: An error occurred while receiving the HTTP
response to http://myservice.mydomain.dk/MyService.svc. This could
be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by
the server (possibly due to the service shutting down). See server
logs for more details.]

I tried looking for logs but i can't find any... also i'm using a WSHttpBinding and an http endpoint.

like image 859
Per Hornshøj-Schierbeck Avatar asked Oct 15 '08 08:10

Per Hornshøj-Schierbeck


3 Answers

As a note, you need to learn how to use the WCF logging utilities:

Logging info.

Config Editor (makes it a snap to setup).

Trace viewer. Totally awesome. Allows multiple services (client and server) to trace and can join them and help you analyse all the details. Lets you get to the root of issues really fast. (Cause when there's a server WCF error, the client is unlikely to get useful data out.)

like image 165
MichaelGG Avatar answered Oct 16 '22 00:10

MichaelGG


Ok i finally found the real problem in my case. It seems exposing enums is not the greatest thing in the world. I either have to set a default value on them, or instead expose the property as an int or whatever integer-type my enum is based on.

Thanks for helping, you had no way of knowing this - i found the enums on the 3rd level in my structure and systematicly removing datamembers one by one was the way i found out. It seems i'm not the only one who ran into this problem - this guy obviously had similar problems :)

http://zianet.dk/blog/2007/11/24/serializing-enums-in-wcf/

like image 40
Per Hornshøj-Schierbeck Avatar answered Oct 15 '22 22:10

Per Hornshøj-Schierbeck


If you are working with WCF+(EF+POCO) then try setting,

ObjectContext.ContextOptions.LazyLoadingEnabled = false;
ObjectContext.ContextOptions.ProxyCreationEnabled = false;
like image 10
indiPy Avatar answered Oct 15 '22 23:10

indiPy