WCF with known type issue - The deserializer has no knowlege of any type that maps to this contract

538 Views Asked by At

Stucked like half of day in just here;

1 ) I returning this class from service;

  public class ServiceResult
  {
    public object Value { get; set; }
    public string ExceptionMessage { get; set; }
    public double Duration { get; set; }
    public int Count { get; set; }
  }

2 )

  public class KResult
  {
    public int Count { get; set; }
    public KResultItem[] Items { get; set; }
  }

3 )

  public class KResultItem
  {
    public string Name { get; set; }
    public string Surname { get; set; }
    public DateTime Date { get; set; }
  }

When i try to set Value to my class 2 and deserialize it boom i got exception.

And I got this exception from wcf;

Exception; Element 'http://schemas.datacontract.org/2004/07/Test.Services:Value' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/Test.Services:KResult'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'KResult' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.

My Interface;

  [ServiceContract]
  public interface IBaseService
  {
    [OperationContract]
    ServiceResult Execute(ServiceCommand serviceCommand);
  }

Seriously i don't know what i'm missing right now but i can't get through this, any help would be awesome and make my day!

First Action

I added suggestion from exception ServiceResult class like this;

  [KnownType(typeof(KResult))]
  [KnownType(typeof(KResultItem))]
  public class ServiceResult
  {
    public object Value { get; set; }
    public string ExceptionMessage { get; set; }
    public double Duration { get; set; }
    public int Count { get; set; }
  }

and still the got same exception.

Thanks already everyone.

0

There are 0 best solutions below