简体   繁体   中英

WCF Service and Inconsistent accessibility

I cannot understand what is wrong. Mistake:"Inconsistent accessibility: return type 'Library.ServiceReference1.Author[]' is less accessible than method '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();
    }

Why do you have [OperationContract] attributes in your DataContract class, I believe those are not valid outside of a ServiceContract decorated class?

If you define read only properties instead of those methods it should work

[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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM