一、服务端重载

  一般写法直接重载,但是会报错,如下。

[ServiceContract]
public interface IService1
{ [OperationContract]
string GetData(int value); [OperationContract]
string GetData(string value); [OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: 在此添加您的服务操作
}

  修改后如下

ServiceContract]
public interface IService1
{ [OperationContract(Name ="GetDataInt")]
string GetData(int value); [OperationContract(Name ="GetDataString")]
string GetData(string value); [OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: 在此添加您的服务操作
}

发现可以了

自动生成代理,方法名字和方法契约名字一样了。

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetDataInt", ReplyAction="http://tempuri.org/IService1/GetDataIntResponse")]
string GetDataInt(int value); [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetDataInt", ReplyAction="http://tempuri.org/IService1/GetDataIntResponse")]
System.Threading.Tasks.Task<string> GetDataIntAsync(int value); [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetDataString", ReplyAction="http://tempuri.org/IService1/GetDataStringResponse")]
string GetDataString(string value); [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/GetDataString", ReplyAction="http://tempuri.org/IService1/GetDataStringResponse")]
System.Threading.Tasks.Task<string> GetDataStringAsync(string value);

二、客户端方法重载

代理类中方法,进行修改

修改前(代码中可以new一个服务实例,然后把方法打出来,F12过去)

 public string GetDataInt(int value) {
return base.Channel.GetDataInt(value);
} public System.Threading.Tasks.Task<string> GetDataIntAsync(int value) {
return base.Channel.GetDataIntAsync(value);
} public string GetDataString(string value) {
return base.Channel.GetDataString(value);
}

修改后

 public string GetData(int value) {
return base.Channel.GetDataInt(value);
} public System.Threading.Tasks.Task<string> GetDataIntAsync(int value) {
return base.Channel.GetDataIntAsync(value);
} public string GetData(string value) {
return base.Channel.GetDataString(value);
}

WCF-方法重载的更多相关文章

  1. WCF实现方法重载

    一.服务契约(包括回调契约)通过指定不同的OperationContract.Name来实现重载方法,当然代码部份还是必需符合C#的重载要求,即相同方法名称,不同的参数个数或参数类型 namespac ...

  2. c# 动态调用WCF方法笔记!

    //动态调用wcf方法 string url = "http://localhost:54379/ServiceWCF.svc"; IDoubleService proxy = W ...

  3. java方法重载(overload)、重写(override);this、super关键简介

    一.方法重载: 条件:必须在一个类中,方法名称相同,参数列表不同(包括:数据类型.顺序.个数),典型案例构 造方重载.  注意:与返回值无关 二.方法重写: 条件: (1)继承某个类或实现某接口 (2 ...

  4. Java之方法重载篇(我重载了,你要如何来调用我。。)

      一.课前引言 请看一下代码,你发现什么特殊之处了吗? public class MethodOverload { public static void main(String[] args) { ...

  5. 【java开发】方法重写和方法重载概述

    类的继承   父类-子类 关键字 extends 新建一个父类 public class Person {     private String name;          private int ...

  6. 方法构造和方法重载之奥特曼与大boss之战

    知识点的总结: 1.类中的方法分为两类:1.普通方法: 2.构造方法. 2.构造方法的格式:  public 类名(数据类型  参数名,...){ } 3.构造方法的用途:  1.实例化对象.  2. ...

  7. JavaScript中的方法重载

    对js有些了解的人都知道,在js中根本就不存在像C#中的那种方法重载,而有的只是方法的覆盖,当你在js中敲入两个或多个同名的方法的时候,不管方法(函数)的参数个数怎么个不同,这个方法名只能属于最后定义 ...

  8. PHP面向对象编程——深入理解方法重载与方法覆盖(多态)

    什么是多态? 多态(Polymorphism)按字面的意思就是“多种状态”.在面向对象语言中,接口的多种不同的实现方式即为多态.引用Charlie Calverts对多态的描述——多态性是允许你将父对 ...

  9. c#方法重载,可选参数,命名参数。

    其实这里没什么可说哦,c++的语法大同小异.先看一段代码. class Program { public static void Test(int a) { Console.WriteLine(&qu ...

  10. java中的方法重载与重写以及方法修饰符

    1. 方法重载Overloading , 是在一个类中,有多个方法,这些方法的名字相同,但是具有不同的参数列表,和返回值 重载的时候,方法名要一样,但是参数类型和参数个数不一样,返回值类型可以相同,也 ...

随机推荐

  1. Pytest权威教程21-API参考-01-函数(Functions)

    目录 函数(Functions) pytest.approx pytest.fail pytest.skip pytest.importorskip pytest.xfail pytest.exit ...

  2. Spring Boot|监控-Actuator

    Spring Boot 为我们提供了一个生产级特性-Actuator,包含很多实际有用的API,下面我们就一起来看看这些API. 一.Actuator 首先在程序中引入Actuator <!-- ...

  3. ssm 项目记录用户操作日志和异常日志

    借助网上参考的内容,写出自己记录操作日志的心得!! 我用的是ssm项目使用aop记录日志:这里用到了aop的切点 和 自定义注解方式: 1.建好数据表: 数据库记录的字段有: 日志id .操作人.操作 ...

  4. sql 数字转换为字符串补0

    select right('00000000000'+convert(varchar(5),123),5) select right('00000000000'+cast(123   as   var ...

  5. MySql的动态语句foreach各种用法比较

    1.单参数List的类型: 上述collection的值为list,对应的Mapper是这样的 2.单参数array数组的类型: 上述collection为array,对应的Mapper代码: 3.自 ...

  6. lnmp一键安装包 多PHP版本使用教程

    ./install.sh mphp 多PHP版本只支持LNMP模式,LNMPA.LAMP模式下不支持!要使用多PHP先安装多PHP版本,在lnmp1.4源码目录下运行:./install.sh mph ...

  7. php中函数 isset(), empty(), is_null() 的区别

    NULL:当你在你的脚本中写下这样一行代码 $myvariable; //此处你想定义一个变量,但未赋值.会有Notice: Undefined variable echo $myvariable + ...

  8. vue后台管理系统兼容问题

    1.兼容 兼容问题主要是指ie9以下的ie浏览器. 2.兼容问题原因 (1)低版本ie不支持编译后的es5 (2)低版本ie不支持Promise 3.解决方法 (1)引入es6-promise &am ...

  9. Vue-CLI 标准开发工具-快速准备环境和创建项目

    https://cli.vuejs.org/zh/ 淘宝镜像安装: npm install -g cnpm --registry=https://registry.npm.taobao.org 2.x ...

  10. 文章后面的QA或FAQ

    QA:question&answer FAQ: Frequently Asked Questions的缩写,中文意思就是“经常问到的问题”