zoukankan      html  css  js  c++  java
  • WCF 之 OperationContract

    这里主要说的是同名异常:

           [ServiceContract]
            public interface IUserInfo
            {
                    [OperationContract]
                    string ShowName(string name);
    
                    [OperationContract]
                    string ShowName();
            }    

    对于以上同名的 OperationContract 如果在客户端引用服务时,将报异常如下:

    解决方法:

     [ServiceContract]
            public interface IUserInfo
            {
                    [OperationContract]
                    string ShowName(string name);
    

              //设置别名 [OperationContract(Name
    ="ShowNameDefault")] string ShowName(); }

    这样客户端引用不报异常,但ShowName的重载,将不起作用,详细引用如下:

    如果需要同名使用ShowName,则需要自定义,而不使用自动生成的:

    class UserInfoServiceClient : ClientBase<IUserInfo>, IUserInfo
          {
                public string ShowName()
                {
                      return this.Channel.ShowNameDefault();
                }
                public string ShowName(string name)
                {
                      return this.Channel.ShowName(name);
                }
    
                #region IUserInfo 不实现操作
    
                public Task<string> ShowNameAsync(string name)
                {
                      throw new NotImplementedException();
                }
    
                public string ShowNameDefault()
                {
                      throw new NotImplementedException();
                }
    
                public Task<string> ShowNameDefaultAsync()
                {
                      throw new NotImplementedException();
                }
    
                #endregion
    
          }
     static void Main(string[] args)
                    {
                          UserInfoServiceClient client = new UserInfoServiceClient();
    
                          Console.WriteLine(client.ShowName());
    
                            Console.ReadKey();
                    }
  • 相关阅读:
    问题 E: C#判断回文字符串
    hdu 1130 How Many Trees? 【卡特兰数】
    The writing on the wall
    字典树的应用
    完全背包
    多重背包
    hdu 2191 【背包问题】
    最长上升子序列 and 最长公共子序列 问题模板
    hdu 4704 Sum 【费马小定理】
    费马小定理
  • 原文地址:https://www.cnblogs.com/yipeng-yu/p/4316391.html
Copyright © 2011-2022 走看看