【问题标题】:Can't have access to classes which implement an interface in client side in WCF无法访问在 WCF 客户端中实现接口的类
【发布时间】:2017-09-23 17:04:24
【问题描述】:

在我的 wcf 服务中,我使用了一个类 (InputClass),其中包含实现接口 (IProperty) 的对象列表:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    OutputClass CanBeImported(InputClass inputObject);
}

[DataContract]
public class InputClass 
{
    [DataMember]
    public List<IProperty> Properties { get; set; }
} 

public interface IProperty
{
}

我有几个实现 IProperty 接口的类

[DataContract]
public class Class1 : IProperty 
{        
    [DataMember]
    public string name1 { get; set; }
} 

[DataContract]
public class Class2 : IProperty 
{        
    [DataMember]
    public int number { get; set; }
} 

问题是我在服务的客户端看不到 class1 和 class2。 如何以客户端可以使用 class1 和 class2 并填充 InputClass 属性的方式将这些类发送到客户端。如果有人帮助我,我将不胜感激。

【问题讨论】:

    标签: c# .net wcf


    【解决方案1】:

    [KnownType(typeof(Class1))][KnownType(typeof(Class2))]添加到IProperty接口。

    【讨论】:

    • 感谢您的回答,但它说属性 KnownType 仅在“类、结构”声明中有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多