Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Method overloading in webservices

Method overloading comes in basics of OOPS. In Method overloading we multiple methods with same name with different Parameters or different return types or different signatures). In Normal code behind of website you may easily overload the method and there is no need of any special code changes, but while you use the overloading in web services, There are some changes needed in service. Without these changes It will show an error while you will try to add service reference in a project. Changes are in two parts:

1. Use MessageName with Overloaded method (Set the MessageName attribute of your webservice)
2. Use Change WebServiceBinding type Keyword (Set your webservice binding: ConformsTo = WsiProfiles.None)

Explanation is given below:

First you have to use the MessageName for using Overloading the Webservice.

Like if you are using the Two add methods then we will have to write MessageName with second method. This is not sufficient to overloading. You need to write

[WebServiceBinding(ConformsTo = WsiProfiles.None)]

After this, service will properly run.

We also can use the Description with Webservice

[WebMethod]
 public int Add(int a, int b)
{
  return a + b; 
} 
[WebMethod(MessageName="abc",Description="Using at adding 4 Parameters")]
 public int Add(int a, int b,int c,int d)
{
   return a + b + c+d;
} 
Share this article   |    Print    |    Article read by 4139 times
Author:
Rohit kakria
I am software developer
Related Articles: No related article
Related Interview Questions: