Reputation: 95
I created one custom library project and it have Employee class to hold employee information.
namespace Test.SampleLib
{
public class Employee
{
public string EmployeeName { get; set; }
public double EmployeeSalary {get; set; }
}
}
I added the Employee class library to the WCF service
public Test.SampleLib.Employee GetDataUsingDataContract(Test.SampleLib.Employee composite)
{
return composite;
}
I tried to consume the service and access the method GetDataUsingDataContract()
ServiceReference1.Service1Client objServiceRef = new ServiceReference1.Service1Client();
Test.SampleLib.Employee objEmployee = new SampleLib.Employee();
objEmployee.EmployeeName = "Kumar";
objEmployee.EmployeeSalary = 30000;
objServiceRef.GetDataUsingDataContract(objEmployee); //Gives errror
The error is
'Argument 1: cannot convert from 'Test.SampleLib.Employee' to 'Test.Web.ServiceReference1.Employee'
Upvotes: 1
Views: 348
Reputation: 480
You need to have [DataContract]
and [DataMember]
attributes on custom data types and its properties you want to expose.
[DataContract]
public class Employee
{
[DataMember]
public string EmployeeName { get; set; }
[DataMember]
public double EmployeeSalary {get; set; }
}
Upvotes: 1