WCF charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)

后端 未结 5 637
误落风尘
误落风尘 2020-12-06 00:09

I\'m hosting a WCF service in IIS 7.5 using .NET 4.0. I also have a WPF application that I am using as my client that was built with Visual Studio 2010 and .NET 4.0. I add

5条回答
  •  心在旅途
    2020-12-06 01:01

    I got this problem after I added a method that returned a collection of instances of a base class that didn't have a [KnownType] attribute that would resolve to a concrete instance. With the [KnownType] attribute in place the problem disappeared.

    [ServiceContract]
    public interface IService {
        [OperationContract]
        IEnumerable GetItems();
    }
    
    [DataContract]
    // [KnownType(typeof(RealItemA))] <--- without these attributes you will get a problem
    // [KnownType(typeof(RealItemB))]
    public class ItemBase {
    }
    
    [DataContract]
    public class RealItemA : ItemBase {
    }
    
    [DataContract]
    public class RealItemB : ITemBase {
    }
    

提交回复
热议问题