0
votes

I have a WCF service called ExceptionsJSONService. Unlike all the other services defined in my solution it can't be instantiated client side in javascript for some reason.

This fails:

var service = new ExceptionsJSONService();

with Object Expected. I've been trying to figure out why this happens and checked all my definitions throughout the project and everything looks fine and is in line with all the other services I've defined (which all work).

Then I checked the svclog file and found an error. The exception type is:

System.Runtime.Serialization.InvalidDataContractException, System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The exception message is:

Type 'System.Data.Entity.DbSet`1[CCMModel.AttachmentDoc]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

CCMModel is the namespace and AttachmentDoc is one of my entities. The issue isn't with AttachmentDoc though. It's just going through the list of entities alphabetically. I renamed an entity from Attachments to RAttachments and it just moved on to throwing an exception with AttachmentDoc.

The thing is, nowhere in my code do I try to serialize any EF entities. All the classes that I serialize have DataContracts. The reason I believe the two are related is the exception occurs right after Open ServiceHost 'ExceptionsJSONService' appears in the svclog.

Anybody encounter this before?

1

1 Answers

0
votes

The problem was caused by a public function defined in the ExceptionsJSONService class. The function is supposed to be public but it was also marked as an Operation Contract.

In the parameter list for the function was our EF DB context object. Because it was in the parameter list for an Operation Contract it caused the service to search for Data Contracts for all the entities associated with the DB context. This caused an exception to be thrown that only showed up in the service trace logs. The exception prevented the service from loading properly so when I would try to instantiate the service client side in javascript it would fail.

Removing the Operation Contract attribute from the function resolved the issue.