一、服务端重载
一般写法直接重载,但是会报错,如下。
[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); }