Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can there be 2 webmethods with same name inside a web service in c#

I was asked a question in interview

can there be 2 webmethods with same name inside a web service in c#.

With function overloading it is possible but interviewer wanted an answer without using function overloading.

My answer was No. IS it correct.Please comment.

like image 849
Rohit Raghuvansi Avatar asked Jan 23 '23 00:01

Rohit Raghuvansi


2 Answers

It can be done as you can read here: http://www.codeproject.com/KB/webservices/OverloadingInWebService.aspx

The reason why you need to do this "special" stuff is just because WSDL does't support the same method names...

Edit: I see the link forgot about the WebServiceBinding:

[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
public class TestService : System.Web.Services.WebService  {

}
like image 133
Zenuka Avatar answered Jan 27 '23 09:01

Zenuka


Actually, it is possible with a little bit of work. The key is changing the message name:

(taken from the link below)

[WebMethod(MessageName="Add_TwoNumbers")]

http://scottwhite.blogspot.com/2005/09/overloading-web-service-methods-in-net.html

like image 23
kemiller2002 Avatar answered Jan 27 '23 09:01

kemiller2002