Welcome to the Understand WCF article series, in this series we are talking about WCF applications. Previous articles explained a few important concepts of WCF applications. You can read the full series here:
- Understand WCF: Part 1: What is SOA, Services and Messages
- Understand WCF: Part 2: Understand RESTful Service
- Understand WCF: Part 3: Create simple WCF Service
- Understand WCF: Part 4: What is Address, Binding, and Contract
- Understand WCF: Part 5: Exception handling in WCF
In this part we will learn the concepts of function overloading in WCF applications. I hope you are familiar with the concept of function overloading, but the concept of function overloading in .NET is a little different in WCF applications. In traditional .NET applications (read Windows app or Web app) we can implement the concept of function overloading by passing various types of parameters where the function name should be the same.
Try to understand the following example.
Code for service contract.
This is the code for the service contract (interface implementation). Try to understand that we have been given the same attribute ("[OperationContract]") in both function declerations.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- namespace WCF
- {
- [ServiceContract]
- public interface IService1
- {
- [OperationContract]
- string AddName(string Name, string LastName);
- [OperationContract]
- string AddName(string Name, string MiddleName, string LastName);
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- namespace WCF
- {
- public class Service1 : IService1
- {
- public string AddName(string Name, string LastName)
- {
- return Name + LastName;
- }
- public string AddName(string Name, string MiddleName, string LastName)
- {
- return Name + MiddleName + LastName;
- }
- }
- }
Here is sample output. We see that it throws an exception. The reason is we cannot use the same name in a function in a WCF application.

Join the conversation! Your thoughts help the community grow.