Wcf serialization
Posted: Mon 21 Feb 2011 13:43
I'm using LinqConnect to fetch data from an Oracle database and then serialize the results through wcf services.
I'm using SerializationMode=Unidirectional because I don't need to trace the object in any way (actually I just need the columns/properties values) and I'm returning a single entity or an array of the same entity type.
My DataContext maps different tables with many relations between them.
I can see that the serialized object still have the EntitySet/EntityRef properties while being serialized and they're always NULL (this is right becuase I don't need the relations): is there a way to tell the designer to not add the DataMember attribute to them?
The serialization works almost all the time: sometimes (and I can't still figure out why) it doesn't work and I get the error "An existing connection was forcibly closed by the remote host". I can't find any problem because the call works from a point in my code but from another it doesn't.
I believe the problem lies between the serialization from my wcf service to my client.
I tried also to explicitily close and reopen the wcf client connection and it seems this solves the problem (but it's more expensive and slower).
What can I do to troubleshoot this problem? Any suggestion is really appreciated!
EDIT: I found the problem with my serialization error using Service Tracing (which I recommend to anyone using wcf):
The error is:
Object graph for type 'CiprosDataContext.Gruppo' contains cycles and cannot be serialized if reference tracking is disabled.'
It seems that the server is trying to serialize the entity relations using the objects retrieved from previous call to my service. So if I could remove the relations from serializations completely may be this problem will be solved. Am I correct?
I'm using SerializationMode=Unidirectional because I don't need to trace the object in any way (actually I just need the columns/properties values) and I'm returning a single entity or an array of the same entity type.
My DataContext maps different tables with many relations between them.
I can see that the serialized object still have the EntitySet/EntityRef properties while being serialized and they're always NULL (this is right becuase I don't need the relations): is there a way to tell the designer to not add the DataMember attribute to them?
The serialization works almost all the time: sometimes (and I can't still figure out why) it doesn't work and I get the error "An existing connection was forcibly closed by the remote host". I can't find any problem because the call works from a point in my code but from another it doesn't.
I believe the problem lies between the serialization from my wcf service to my client.
I tried also to explicitily close and reopen the wcf client connection and it seems this solves the problem (but it's more expensive and slower).
What can I do to troubleshoot this problem? Any suggestion is really appreciated!
EDIT: I found the problem with my serialization error using Service Tracing (which I recommend to anyone using wcf):
The error is:
Object graph for type 'CiprosDataContext.Gruppo' contains cycles and cannot be serialized if reference tracking is disabled.'
It seems that the server is trying to serialize the entity relations using the objects retrieved from previous call to my service. So if I could remove the relations from serializations completely may be this problem will be solved. Am I correct?