Method or Operation overloading is one of the most important feature of OOPS. In programming languages like C, C++ and C#, this feature is heavily used by developers. While writing Service definition you may come across when you need to overload operations.
Let us go ahead and write Service with overloaded function as following. In below ServiceContract I am creating two methods and overloading them with different parameters. To achieve overloading at Service side I set Name parameter of both function as follows:
[OperationContract(Name = "GetIntegerData")] string GetData(int value); [OperationContract(Name = "GetStringData")] string GetData(string value);
So to consume service in my client application, you need to use the method name you specified in the Name attribute. The code in my client application will be:
ServiceReference1.Service1Client client = new Client.ServiceReference1.Service1Client(); Console.WriteLine(client.GetIntegerData(5)); Console.WriteLine(client.GetStringData("pranay"));
Summary : You can easily use method overloading in WCF service with the help of Name field in OperationContract attribute.
Hope this will help !!!