1. 本来在WebService中这样写的重载方法,如下所示:

[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class DataObjectWebService : System.Web.Services.WebService
    {
        [WebMethod(EnableSession = true)]
        public int Add(int a, int b)
        {
            return a + b;
        }

[WebMethod(EnableSession = true)]
        public int Add(int a, int b, int c)
        {
            return a + b + c;
        }
    }

在调用WebService时,抛错:“Int32 Add(Int32, Int32, Int32) 和 Int32 Add(Int32, Int32) 同时使用消息名称“Add”。使用 WebMethod 自定义特性的 MessageName 属性为方法指定唯一的消息名称。”

2. 原来,必须在类中指示不支持1.1标准并且在方法中指定MessageName来创建唯一的别名。可以这样来解决,如下所示,这样在客户端调用时,就可以调用WebService不同的重载方法了。

[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.None)]
    public class DataObjectWebService : System.Web.Services.WebService
    {
        [WebMethod(EnableSession = true, MessageName= "Add1")]
        public int Add(int a, int b)
        {
            return a + b;
        }

[WebMethod(EnableSession = true, MessageName= "Add2")]
        public int Add(int a, int b, int c)
        {
            return a + b + c;
        }
    }

其中,

WebServiceBindingAttribute.ConformsTo 属性:获取或设置绑定声称所符合的 Web 服务互操作性 (WSI) 规范。

WsiProfiles.None 表示 Web 服务未提出任何一致性声称。

WsiProfiles.BasicProfile1_1 表示 Web 服务声称符合“WSI 基本概要”1.1 版。

WebMethodAttribute.MessageName 属性:在传递到 XML Web services 方法和从 XML Web services 方法返回的数据中用于 XML Web services 方法的名称。默认值是 XML Web services 方法的名称。 另外,MessageName 属性可用于为方法或属性名创建别名。MessageName 属性 (Property) 最常用来唯一标识多态方法。默认情况下,MessageName 设置为 XML Web services 方法的名称。因此,如果 XML Web services 包含两个或更多同名的 XML Web services 方法,则可唯一确定各个 XML Web services 方法,处理方法是将 MessageName 设置为 XML Web services 内的唯一名称,而不用在代码中更改实际方法的名称。数据在传递到 XML Web services 时通过请求发送,而在返回时则通过响应发送。在请求和响应中,用于 XML Web services 方法的名称是其 MessageName 属性 (Property)。与 XML Web services 方法关联的消息名称必须在 XML Web services 内是唯一的。如果在客户端调用初始方法后添加同名但具有不同参数的新 XML Web services 方法,则应为新方法指定不同的消息名称,但应原样保留初始消息名称,以确保与现有客户端兼容。

如何在WebService中重载方法的更多相关文章

  1. java面试题0001-区分类中重载方法的依据是什么?

    到底是根据什么来区分类中重载的方法? A:不同的返回值类型. B:不同的参数类型. C:不同的访问权限. D:不同的参数名称. 解析: Step1.我们先在DifferentiateReload类中创 ...

  2. ajax调用webService中的方法

    页面代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx. ...

  3. 【转】利用ScriptManager实现Javascript调用WebService中的方法

    原文发布时间为:2009-07-01 -- 来源于本人的百度文章 [由搬家工具导入] 前台调用后台方法,或者后台调用前台方法。ScriptManager实现 开发过程中,总想在前台直接调用后台的met ...

  4. WebService中方法的重载

    阅读目录 一:WebService中的方法是否允许重载? 二:为什么WebService中不支持方法的重载? 三:如何解决WebService中方法的重载? 一:WebService中的方法是否允许重 ...

  5. C# Webservice中如何实现方法重载--(方法名同名时出现的问题)

    本文摘抄自:http://blog.sina.com.cn/s/blog_53b720bb0100voh3.html 1.Webservice中的方法重载问题(1)在要重载的WebMethod上打个M ...

  6. WebService中方法的相关注意事项

    2014-11-14 在WebService中定义方法,有一些注意的地方: (1) 方法上面需要增加 [WebMethod] 属性,标志该方法是一个WebService方法: (2)方法的返回值可以为 ...

  7. WebService中使用自定义类的解决方法(5种)

    转自:http://www.cnblogs.com/lxinxuan/archive/2007/05/24/758317.html Demo下载:http://files.cnblogs.com/lx ...

  8. 在webservice中传递Hashtable

    webservice中不支持hashtable的数据类型,那么如何在webservice中传递hashtable呢?我们可以通过将hashtable转化为webservice中支持的数组的类型来进行传 ...

  9. flex调用webservice中的datatable结果写入datagrid

    webservice配置文件 <appSettings> <add key="sqlConDuke" value="server=10.9.34.88; ...

随机推荐

  1. SQLAlchemy基本使用(Flask中)

    SQLAlchemy介绍 SQLAlchemy是一个基于Python实现的ORM框架. 该框架建立在 DB API之上,使用关系对象映射进行数据库操作,简言之便是:将类和对象转换成SQL,然后使用数据 ...

  2. Python的 numpy中 numpy.ravel() 和numpy.flatten()的区别和使用

    两者所要实现的功能是一致的(将多维数组降为一维), 两者的区别在于返回拷贝(copy)还是返回视图(view),numpy.flatten() 返回一份拷贝,对拷贝所做的修改不会影响(reflects ...

  3. 【LeetCode】131. Palindrome Partitioning

    Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...

  4. Everything:速度最快的文件名搜索工具

    http://xbeta.info/everything-search-tool.htm Everything(官网|中文主页|教程)是速度最快的文件名搜索软件.其速度之快令人震惊,百G硬盘几十万个文 ...

  5. 【js与jquery】jquery循环滚动新闻

    2.html代码: <h3>最新动态</h3> <div class="scrollNews" > <ul> <li>& ...

  6. Android 加新的页面

    工程右键->New->Other->Android Activity

  7. linux查看与开启sshd服务

    1.首先通过物理终端进入到linux上,手工检查ssh发现没运行/etc/init.d/sshd statussshd is stopped 手工启动服务,发现报告权限错误./etc/init.d/s ...

  8. ubuntu中pip安装redis-py及pip的使用

    安装redis-py的前提是已经将redis成功安装,redis安装过程请看博文 ubuntu14安装redis 1.安装pip sudo apt-get install python-pip 2.使 ...

  9. cocos2dx 3.x fullPathForFilename及isFileExist在ios/mac下与win32下行为不同

    一,fullPathForFilename 项目先开发了ios/mac版本,这两天想把win32工程也配好,但遇到了部分资源无法正确找到的问题. 进一步观察发现,对于那些找不到的资源路径,fullPa ...

  10. 甲骨文关闭OpenSSO后,OpenAM成为其继续者

    消息来源:http://os.51cto.com/art/201003/190108.htm                                        OpenAM主页连接: ht ...