WCF已知类型,不起作用

时间:2012-03-15 08:41:35

标签: wcf types

[ServiceContract]
[ServiceKnownType(typeof(DBReq))]
public interface IDAService
{


[DataContract]
[KnownType(typeof(IDataParameterCollection))]
public class DBReq : DBAccess
{

    [DataMember]
    public IDataParameterCollection DataParams
    {
    ...

为什么DataParams在我的客户端反序列化为Object类型?

1 个答案:

答案 0 :(得分:1)

您的[KnownType(typeof(IDataParameterCollection))]不正确。您应该将实现类型传递给KnownType属性。

例如

public class MyType : IDataParameterCollection {...}

[DataContract]
[KnownType(typeof(MyType))]
public class DBReq : DBAccess
{

    [DataMember]
    public IDataParameterCollection DataParams
    {
    ...