Common error resolution for WCF distributed Development (8): Inconsistent accessibility inconsistent accessibility

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.