In the design of the data contract class, and use its parameters to implement client and server data interaction, edit the service class, the following error occurred:
Error 1 Inconsistent accessibility: parameter type 'WCFService.UserDataContract' is less accessible than method 'WCFService.IWCFService.AddNewUser(WCFService.UserDataContract)' E:\CodesVs2008\WCFServiceDataContractFrankXuLei\WCFServiceFrankXuLei\WCFService\WCFService.cs 19 14 WCFService
Other similar error messages:
Error 2 Inconsistent accessibility: return type 'WCFService.UserDataContract' is less accessible than method 'WCFService.IWCFService.GetUserByName(string)' E:\CodesVs2008\WCFServiceDataContractFrankXuLei\WCFServiceFrankXuLei\WCFService\WCFService.cs 22 26 WCFService
Solution:
This error is due to the inconsistency of the Access property settings of the data contract class to the service contract Access property, the service contract interface's access behavior public, and the service class is public, and the data contract class has no access attribute for life.
We add the data contract class to the Public keyword. The sample code is as follows:
[DataContract]//数据契约属性声明
public class UserDataContract
{
[DataMember(Name = "UserName")]//数据成员标记,支持别名定 义
public string Name
{
get;
set;
}
[DataMember(Name = "UserEmail")]//数据成员标记,支持别名定 义
public string Email
{
get;
set;
}
[DataMember]//数据成员标记
public string Mobile
{
get;
set;
}
//没有[DataMember]声明,不会被序列化
public string Address
{
get;
set;
}
}