转:Web Service 方法重载(Overloads),原来 Web Service 是支持重载方法的!

来源:互联网 发布:软件限制策略 编辑:程序博客网 时间:2024/05/16 17:43

转自: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
        [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;
        }
2、修改类属性ConformsTo
        [WebService(Namespace = "http://Sample.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.None)]
        [ToolboxItem(false)]
        public class Math : System.Web.Services.WebService
        {...}
原创粉丝点击