a. 服务端1.服务端 契约用OperationContract的Name实现重载using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text; namespace WCF.Chapter2.Overloading.Host { [ServiceContract] public interface IContract { [OperationContract(Name = "say1")] string say(); [OperationContract(Name = "say2")] string say(string str); } }2.服务实现using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.Text;namespace WCF.Chapter2.Overloading.Host.Service{ // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“Service1”。 public class Service1 : IContract { public string say() { return "老鼠扛刀,满街找猫"; } public string say(string str) { return str; } }}3.服务寄宿using System;using System.ServiceModel;using WCF.Chapter2.Overloading.Host.Service;namespace WCF.Chapter2.Overloading.Host{ class Program { static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(Service1))) { host.Opened += delegate { Console.WriteLine("服务已开启..."); }; host.Open(); Console.ReadLine(); } Console.WriteLine("服务已关闭..."); Console.ReadLine(); } }}4.终结点设置b. 客户端1.客户端契约 这个很重要需要和服务端分开不能用同一个契约,而是实现了一个等效契约,所以此处说明终结点三要素A,B,C 的A,B必须一模一样但是C只要等效就可以using System;using System.ServiceModel;namespace WCF.Chapter2.Overloading.Client{ [ServiceContract] public interface IContract { [OperationContract(Name = "say1")] string say(); [OperationContract(Name = "say2")] string say(string str); }}2.客户端代理 本质也是channelfactory.createchannelusing System;using System.ServiceModel;namespace WCF.Chapter2.Overloading.Client{ public class ClientProxy : ClientBase , IContract { public ClientProxy() { } public ClientProxy(string configurationName) : base(configurationName) { } public string say() { return base.Channel.say(); } public string say(string str) { return base.Channel.say(str); } }}3.客户端终结点配置 4.调用代码using System;using System.ServiceModel;namespace WCF.Chapter2.Overloading.Client{ public class ClientProxy : ClientBase , IContract { public ClientProxy() { } public ClientProxy(string configurationName) : base(configurationName) { } public string say() { return base.Channel.say(); } public string say(string str) { return base.Channel.say(str); } }}