转自:http://zhhot.spaces.live.com/Blog/cns!6556C5D5C7889AD7!313.entry
Web Service 方法重载(Overloads)
在Web service 中重载方法,默认是不支持的,这是因为WebMethod特性的MessageName属性使XML Web services能够唯一确定使用别名的重载方法。除非另外指定,默认值是方法名称。当指定MessageName时,结果SOAP消息将反映该名称,而不是实际的方法名称。所以我们只需作2点改动:
1、修改方法属性MessageName
1、修改方法属性MessageName
[WebMethod(
MessageName = "AddInt")]
public int Add(int a, int b)
{
return a + b;
}
[WebMethod( MessageName = "AddFloat")]
public int Add(float a, float b)
{
return a + b;
}
public int Add(int a, int b)
{
return a + b;
}
[WebMethod( MessageName = "AddFloat")]
public int Add(float a, float b)
{
return a + b;
}
2、修改类属性ConformsTo
[WebService(Namespace = "
http://Sample.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[ToolboxItem(false)]
public class Math : System.Web.Services.WebService
[WebServiceBinding(ConformsTo = WsiProfiles.None)]
[ToolboxItem(false)]
public class Math : System.Web.Services.WebService
{...}

本文介绍了如何在WebService中实现方法重载。通过设置MessageName属性为不同的值,并修改类属性ConformsTo为None,可以成功地实现方法的重载。
,原来 Web Service 是支持重载方法的!&spm=1001.2101.3001.5002&articleId=4934926&d=1&t=3&u=bcecb03d95b941dd81004f1cc2f7b68d)
288

被折叠的 条评论
为什么被折叠?



