Click here to Skip to main content
13,357,363 members (70,877 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 1 Dec 2010

Method overloading in WCF

, 19 Dec 2010
Rate this:
Please Sign up or sign in to vote.
Method overloading in WCF

I found a scenario where I have to implement two methods with the same name, i.e Function overloading. But when I implement that, I got an error "System.InvalidOperationException"

System.InvalidOperationException: Cannot have two operations in the same 
contractwith the same name, methods GetData and GetData in type 
WcfServiceLibrary.IService1 violate this rule.


To resolve this issue, you just need to use a meaningful name for the method by using NAME field available in OperationContract attribute. So you need to give a name to both or one of the methods to avoid this problem. As you can see in the below code that I did in control IService.cs interface.

        [OperationContract(Name = "GetIntegerData")]
        string GetData(int value);

        [OperationContract(Name = "GetStringData")]
        string GetData(string value);

So after doing the change, I get live service but the name of the method gets change by the name specified in the  Name attribute which you can see in the below image:

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 is:

            ServiceReference1.Service1Client client = new Client.ServiceReference1.Service1Client();


You can easily resolve the issue of method overloading in WCF service with the help of Name field in OperationContract attribute.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pranay Rana
Software Developer (Senior) GMind Solusion
India India

Microsoft C# MVP (12-13)

Hey, I am Pranay Rana, working as a ITA in MNC. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5.5 years now.

For me def. of programming is : Programming is something that you do once and that get used by multiple for many years

You can visit my blog

StackOverFlow -
My CV :-


You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
parminder sidhu30-Jan-14 2:06
memberparminder sidhu30-Jan-14 2:06 
GeneralMy vote of 1 Pin
Marcelo Lujan [El Bebe.Net ]2-May-12 14:43
memberMarcelo Lujan [El Bebe.Net ]2-May-12 14:43 
GeneralReason for my vote of 2 If all calls to the method have to u... Pin
Ryan Gamal17-Jan-11 0:36
memberRyan Gamal17-Jan-11 0:36 
GeneralReason for my vote of 5 Good One! Pin
Anupama Roy11-Jan-11 19:22
memberAnupama Roy11-Jan-11 19:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 19 Dec 2010
Article Copyright 2010 by Pranay Rana
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid