Error: does not implement interface member

27.9k views Asked by At

I am trying to build Restful WCF services, i was stuck with below error

error CS0535: 'WcfPOC.RestServiceImpl' does not implement interface member 'WcfPOC.IRestServiceImpl.SaveEmployee(WcfPOC.RequestData)'

below is my code.

RestServiceImpl .svc.cs

namespace WcfPOC
{
    public class RestServiceImpl : WcfPOC.IRestServiceImpl
    {

        public string SaveEmployee(ResponseData rData) {
            try
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    SPWeb web = site.OpenWeb();
                    SPListItemCollection listItems = web.Lists["Emply"].Items;
                    SPListItem item = listItems.Add();
                    item["Name"] = rData.Name;
                    item["Email"] = rData.Email;
                    item["EmployeeID"] = rData.EmployeeID;
                    item["Role"] = rData.Role;
                    item.Update();
                }
                return "Success";
            }catch(Exception e){
                return "Error"+e;
            }
        }
    }

    [DataContract]
    public class RequestData
    {
        [DataMember]
        public string Name { get; set; }
        public string Email { get; set; }
        public string EmployeeID { get; set; }
        public string Role { get; set; }
    }

    [DataContract]
    public class ResponseData
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public string EmployeeID { get; set; }
        public string Role { get; set; }
    }
}

IRestServiceImpl.cs

namespace WcfPOC
{
    public class IRestServiceImpl
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IRestServiceImpl" in both code and config file together.
        [ServiceContract]
        public interface IRestServiceImpl
        {            
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SaveEmployee")]
            string SaveEmployee(RequestData rdata);

        }
    }

}

any help is apricated.

1

There are 1 answers

0
user3041160 On

Interface :

string SaveEmployee(RequestData rdata);

Class

public string SaveEmployee(ResponseData rData)

Your compilation error comes from you use two different classes in your method signatures between the interface and the class : RequestData vs ResponseData. You probably do not need to use two classes with the same design. Only one should be enough ?