C# Webservice中方法名相同,实现重载的方法
假设有两个方法,他们名称相同,只是重载而已,如下:
[WebMethod] public string HelloWorld() { return "yes"; } [WebMethod] public string HelloWorld(string msg) { return msg; }
方法直接这样子写是会报错的,提示会叫你添加MessageName属性,如下:
[WebMethod(MessageName="method1")] public string HelloWorld() { return "yes"; } [WebMethod(MessageName="method2")] public string HelloWorld(string msg) { return msg; }
到这里问题还解决不了,要在当前Webservice的服务的[WebService(Namespace = "http://tempuri.org/")]的下面加
[WebServiceBinding(ConformsTo = WsiProfiles.None)],注意它原先是有值的,直接替换这一行就行了