Method Overloading
Method overloading allows us to have two or more methods of the same name but with different arguments (signature) in the same class. The concept of method overloading in Web Method of Web Service is different, as we use MessageName property to achieve method overloading in a Web Service. MessageName property is basically used to uniquely identify the individual XML Web Service methods.
Note
This is a very common interview question as well: Is it possible to overload a web method in a web service? The answer is yes, you need to use MessageName property for this.
I’ve discussed MessageName property in my previous article. Before starting this article, follow the journey of the Web Services series,
- Getting Started With ASP.NET Web Services - Part One
- Consuming A Web Service In ASP.NET – Part Two
- Manage Session State In Web Service - Part Three
- Properties Of WebMethod attribute in Web Service - Part Four
In order to achieve method overloading, let’s make a copy of AddName method. These two AddName methods are identical as they have the same name, they have the same number type, and the same kind of parameters.

Now let’s build your Web Service, see what happened.

We got a compilation error, which is because if we want to overload methods, they are different- at least numbers, types or kind of the parameters. Thus, you need to overload these AddName methods within the Web Service, based on the number of parameters.

Therefore, the first one, AddName method, has two parameters. Let’s makea second AddName method, which has three parameters. Thus, in the second method, make three parameters, so the first method is going to add two strings and the second method is going to add three strings.

Now, again build this Web Service.

Build has been successful.

Now, let’s view this web Service in a Browser Window. Right click Web Service and choose View in the Browser.

Consider the following screenshot, where we got an error with AddName method, which has three string parameters and the other one has two string parameters, using the same message name, which is AddName.
















Hadshana KamalanathanPosted Jul 22, 2018, 1:27 AM
Good one..
Santhakumar MunuswamyPosted Jun 25, 2016, 3:04 AM
Nice share
AniPosted Jun 16, 2016, 3:10 AM
Nice explanation. Thank you
Bhavik PatelPosted Jun 15, 2016, 10:19 PM
good one!
Vignesh ManiPosted Jun 15, 2016, 8:42 AM
Nice
Thiruppathi RPosted Jun 15, 2016, 1:05 AM
Nice Sharing..
Debasis SahaPosted Jun 15, 2016, 12:44 AM
Good share..
RajaPosted Jun 15, 2016, 12:16 AM
Good One...