net Web Service 方法重载
在Web service 中重载方法,默认是不支持的,这是因为WebMethod特性的MessageName属性使XML Web services能够唯一确定使用别名的重载方法。除非另外指定,默认值是方法名称。当指定MessageName时,结果SOAP消息将反映该名称,而不是实际的方法名称。下面是我用的Webservice 方法的重载:
namespace WebMothed_重载 {
///
/// Summary description for Service1
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService {
///
/// Summary description for Service1
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService {
[WebMethod(MessageName="a")]
public string HelloWorld() {
return "Hello World";
}
[WebMethod(MessageName="b")]
public string HelloWorld(string str) {
return "Hello World"+str;
}
}
}
public string HelloWorld() {
return "Hello World";
}
[WebMethod(MessageName="b")]
public string HelloWorld(string str) {
return "Hello World"+str;
}
}
}
主要注意修改两个地方:
1、修改方法属性MessageName
1、修改方法属性MessageName
[WebMethod(MessageName="a")]
public string HelloWorld() {
return "Hello World";
}
[WebMethod(MessageName="b")]
public string HelloWorld(string str) {
return "Hello World"+str;
}
2、修改类属性ConformsTo
public string HelloWorld() {
return "Hello World";
}
[WebMethod(MessageName="b")]
public string HelloWorld(string str) {
return "Hello World"+str;
}
2、修改类属性ConformsTo
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService {...}
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService {...}