Using Overloaded Operations in your ServiceContract

A common programming paradigm with objects is the use of overloaded methods. That is, multiple methods with the same name, but different parameters. In reality though, this paradigm is syntactic sugar on top of a compiler that is generating different fully-qualified names.

It may be that you’ve done your service-oriented scrub and decided you want to expose two overloaded methods. From a service-orientation perspective, the compiler isn’t adding extra qualifications to differentiate the methods. Our default action generation is based on the operation name, which defaults to the name of your method. As such, in order for a client (and our dispatcher) to distinguish between multiple overloaded methods, you need to provide them with unique names. For example:

interface ICalculator

[OperationContract(Name= "Add_Int")]
int Add(int x, int y);

[OperationContract(Name= "Add_Long")]
long Add(long x, long y);


Leave a Reply

Your email address will not be published. Required fields are marked *