Search This Blog

Friday, September 2, 2011

Method Overloading in ASMX and WCF services

Both ASMX and WCF services do not support method overloading by default. However, it is possible to enable method overloading with ASMX or WCF service by decorating a ASMX web method or a WCF method as follows.

In ASMX:


[WebMethod (MessageName="HelloWorld")]

public string HelloWorld()
{
   return "HelloWorld";
}

[WebMethod (MessageName="HelloWorldWithName")]

public string HelloWorld(string name)
{
   return "HelloWorld " + name;
}

In WCF:


[ServiceContract]

public interface IMyCalculator
{
[OperationContract(Name="AddFloats")]
float Add(float operand1, float operand2);

[OperationContract(Name="AddIntegers")]

int Add(int operand1,int operand2);
}

No comments:

Post a Comment