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

  • 相关阅读:
    eclipse中创建maven项目
    Java Build Path Entries 没有maven怎么办
    Eclipse导入Maven项目详解(新手初学)
    windows下Tomcat详细安装配置教程
    Tomcat 下载安装与配置
    Python 生成个性二维码
    ERROR 1010 (HY000): Error dropping database (can't rmdir './nsd', errno: 39)
    发邮件的python脚本
    Centos7 安装MySQL 5.7 (通用二进制包)
    js数字简写
  • 原文地址:https://www.cnblogs.com/wudequn/p/7081143.html
Copyright © 2020-2023  润新知