我在面试中被问到一个问题
在c#中的Web服务中可以有2个具有相同名称的web方法。
有了函数重载,但是面试官可以在不使用函数重载的情况下获得答案。
我的答案是否正确。请发表评论。
答案 0 :(得分:3)
实际上,只需要一点点工作就可以了。关键是更改消息名称:
(取自以下链接)
[WebMethod(MessageName="Add_TwoNumbers")]
http://scottwhite.blogspot.com/2005/09/overloading-web-service-methods-in-net.html
答案 1 :(得分:3)
可以在这里阅读: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 {
}
答案 2 :(得分:2)
不,您不能拥有两个名称相同且签名相同的方法。这没有多大意义。
答案 3 :(得分:1)
我猜你可以将它们作为不同的外部名称公开(如果可能的话)。