WCF DataContract Inheritance

Akiii
Posted by Akiii under WCF category on | Points: 40 | Views : 3006
First we create WCF service application,

Iservice File Code :-
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(clsCustomer2 objcustomer);
}

[DataContract]
public class clsCustomer1
{
[DataMember]
public string firstname { get; set; }

[DataMember]
public string lastname { get; set; }
}

[DataContract]
public class clsCustomer2: clsCustomer1
{
[DataMember]
public string salary { get; set; }
}


Then we write the implementation of the interface in the service class.
Service file code:-
public class Service1 : IService1
{
public string GetData(clsCustomer2 objcustomer)
{
return objcustomer.firstname + "---" + objcustomer.lastname + "---" + objcustomer.salary;
}
}



Then I created a console client and tested the service. I added a service reference of the above service and created a proxy class.
Client code :-
class Program
{
static void Main(string[] args)
{
Service1Client objClient = new Service1Client();

clsCustomer2 objc = new clsCustomer2();
objc.firstname = "Akiii";
objc.lastname = "lethal";
objc.salary = "10";

string str = objClient.GetData(objc);

Console.WriteLine(str);
Console.ReadLine();
}
}



Try this and if you find any problem in the above code, please let me know !


Thanks and Regards
Akiii

Comments or Responses

Login to post response