When I start my service, I got an exception:
The server encountered an error processing the request. Exception message: "It is not possible to serialize a parameter of type System.Data.Entity.DynamicProxies.Cosik_14C2 ..." (for the operation "GetCosik", the contract is "ICosikService"), because it is not the exact type "Project.Domain.Entities.Cosik 'in the method signature and not in the collection of known types. To serialize a parameter, add the type to the collection of known types for the operation using ServiceKnownTypeAttribute.' For more details see Server Logs.
I am new to WCF and Entity Framework services and I would appreciate any help / suggestions.
I am using Entity Framework 4.1. Using the first code database with two tables:
[DataContract(IsReference=true)]
public class Cosik
{
[DataMember]
public int cosikID { get; set; }
[DataMember]
public string title { get; set; }
[DataMember]
public int DifficultyID { get; set; }
[DataMember]
public virtual Difficulty Difficulty { get; set; }
}
[DataContract(IsReference=true)]
public class Difficulty
{
[DataMember]
public int DifficultyID { get; set; }
[DataMember]
[Required]
public string NameToDisplay { get; set; }
}
WCF RESTful. :
[ServiceContract]
public interface ICosikService
{
[OperationContract]
[ApplyDataContractResolver]
[WebGet(UriTemplate = "/cosik")]
Cosik GetCosik();
}
public class RecipeService : IRecipeService
{
private ICosikRepository cosikRepo;
...
public Cosik GetCosik()
{
Cosik c = cosikRepo.GetById(1);
return c;
}
ApplyDataContractResolverAttribute, : http://msdn.microsoft.com/en-us/library/ee705457.aspx, [ApplyDataContractResolver] GetCosik. .
, ?