WCF服务和不一致的可访问性

时间:2010-12-01 20:57:44

标签: c# wcf

我无法理解什么是错的。错误:“不一致的可访问性:返回类型'Library.ServiceReference1.Author []'比方法'Library.Funcs.GetAuthorsList()'”

更难访问
//class in DLL    
[DataContract]
public class Author
{
    [DataMember]
    private string FN, N, P;
    [OperationContract]
    public string GetFamilyName()
    {
        return FN;
    }
    [OperationContract]
    public string Name()
    {
        return N;
    }
    [OperationContract]
    public string Patronymic()
    {
        return P;
    }
    public Author(string familyName, string name, string patronymic)
    {
        FN = familyName;
        N = name;
        P = patronymic;
    }
}
//in service
public Author[] GetAuthorsList()
    {
        return DB.Singleton.GetAuthorsList().ToArray();
    }

1 个答案:

答案 0 :(得分:1)

为什么在DataContract类中有[OperationContract]属性,我相信这些属性在ServiceContract装饰类之外是无效的?

如果您定义只读属性而不是那些方法,那么它应该起作用

[DataContract]
public class Author
{
    [DataMember]
    private string FN, N, P;

    public string FamilyName
    {
        get { return FN; }
    }

    public string Name
    {
        get { return N; }
    }

    public string Patronymic
    {
        get { return P; }
    }

    public Author(string familyName, string name, string patronymic)
    {
        FN = familyName;
        N = name;
        P = patronymic;
    }
}