Reputation: 1415
I have a WCF service project that is faulting when I am trying to eager load entities. (.Include).
My setup is like this:
I have spent some time trying to fix this serialization issue when I am eager loading entities.
Here is where I am now. The below works:
[OperationContract]
[FaultContract(typeof(HandleException))]
[ApplyProxyDataContractResolver]
List<Item> GetItems();
using (var dbContext = new MyEntities())
{
dbContext.Configuration.LazyLoadingEnabled = false;
return dbContext.Items.ToList();
}
And displays this:
But this faults and gives the generic error message
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
This is what is throwing the exception
return dbContext.Items.Include(x => x.Category).ToList();
I have tried changing the return type to Item
and then something like this
return dbContext.Items.Include(x => x.Category).FirstOrDefault(t => t.Category.CategoryId == t.CategoryId);
And I have added [CyclicReferencesAware(true)]
but the test client is still bombing out.
Categories are a self referencing hierarchy -- I think that is why it can't handle it.
How can I resolve this?
Thanks.
Upvotes: 0
Views: 447
Reputation: 16498
WcfTestClient.exe can't handle cyclic references - have you tried testing with your own custom code?
Upvotes: 1