zoukankan      html  css  js  c++  java
  • WCF方法重载

    一、服务端重载

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

    [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);
            }

  • 相关阅读:
    用C#实现宽带重新拨号
    CALLBACK FUNCTION 回调函数
    编译程序 VS 解释程序
    《围城》读书笔记
    鼠标点击器
    工作与找工作的日子
    Windows 7下VS2003的查找无响应问题
    收藏几句关于程序的名言
    static知识小结
    如何定义和实现一个类的成员函数为回调函数(转)
  • 原文地址:https://www.cnblogs.com/wudequn/p/7081143.html
Copyright © 2011-2022 走看看