一、服务端重载

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

[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. 在Git中如何撤销上一次的commit

    有的时候我们一不小心就git commit -m ‘commit message info’解决办法,很简单,只需执行git reset HEAD~这条命令即可,即能保证你原本的修改还在,也能撤销本次 ...

  2. Language Modeling with Gated Convolutional Networks(句子建模之门控CNN)--模型简介篇

    版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/liuchonge/article/deta ...

  3. C#文件或文件夹压缩和解压

    C#文件或文件夹压缩和解压方法有很多,本文通过使用ICSharpCode.SharpZipLib.dll来进行压缩解压 1.新建一个winform项目,选择项目右键 管理NuGet程序包,搜索ICSh ...

  4. GIS地理工具案例教程——批量去除多边形的之间的间隙

    GIS地理工具案例教程--批量去除多边形的之间的间隙 商务合作,科技咨询,版权转让:向日葵,135-4855__4328,xiexiaokui#qq.com 问题:几乎所有的手工生产的数据,都存在多边 ...

  5. Android: ListView与Button的共存问题解决

    ListView 和 其它能触发点击事件的widget无法一起正常工作的原因是加入其它widget后,ListView的itemclick事件将无法触发,被其它widget的click事件屏蔽.   ...

  6. Nessus更新到8.5.0

    Nessus更新到8.5.0   此次更新,主要涉及以下变化: (1)Nessus的用户注册和激活流程进行简化.用户可以在Nessus软件中直接进行注册和激活. (2)Nessus报告生成功能得到加强 ...

  7. 如何发布H5界面可以让公网访问

    本文链接:https://blog.csdn.net/u013310119/article/details/81233560问题背景:手机APP里的H5界面要发布到公网,提供给第三方APP调用. 解决 ...

  8. spring2.5 jdk1.8

    今天运行一个14年基于spring2.5的项目,出现下面错误 Unexpected exception parsing XML document from class path resource .. ...

  9. Spring cloud微服务安全实战-6-3JWT改造之网关和服务改造

    网关上认证去做哪些改造 在网关上用jwt去解析用户信息,而不再发送校验令牌的请求了. 之前的时候网关上实际上写了很多的代码 包括认证,发check_token去把token请求,换成用户信息. 这俩是 ...

  10. LeetCode_219. Contains Duplicate II

    219. Contains Duplicate II Easy Given an array of integers and an integer k, find out whether there ...