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

  • 相关阅读:
    HTML初识
    使用python操作Memcache、Redis、RabbitMQ、
    使用salt-cloud创建虚拟机
    运维堡垒机----Gateone
    ELK日志分析系统
    Python MySQL API
    浅谈Java中static作用--转
    oracle如何设置最大连接数
    转--oracle查看允许的最大连接数和当前连接数等信息
    oracle 查看未关闭连接
  • 原文地址:https://www.cnblogs.com/wudequn/p/7081143.html
Copyright © 2011-2022 走看看