我在面试中被问到一个问题。
在c#的web服务中,可以有2个同名的webmethods吗?
使用函数重载是可能的,但面试官希望在不使用函数重载的情况下得到答案。
我的回答是不。这是correct.Please评论吗。
发布于 2009-11-10 21:42:42
不能,你不能有两个同名相同签名的方法。这没有多大意义。
发布于 2009-11-10 21:45:34
实际上,这是可能的,只要做一点工作。关键是更改消息名称:
(取自下面的链接)
[WebMethod(MessageName="Add_TwoNumbers")]http://scottwhite.blogspot.com/2005/09/overloading-web-service-methods-in-net.html
发布于 2009-11-10 21:49:41
你可以在这里读到:http://www.codeproject.com/KB/webservices/OverloadingInWebService.aspx
之所以需要做这种“特殊”的事情,只是因为WSDL不支持相同的方法名称……
编辑:我看到忘记WebServiceBinding的链接:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
public class TestService : System.Web.Services.WebService {
}https://stackoverflow.com/questions/1708038
复制相似问题