zoukankan      html  css  js  c++  java
  • WCF Basic(1)操作重载

         现网上关于WCF所谓是很多,但好书很少.Programming WCF Services 应该算是一本非常好的书。结合书和代码总结一下.

    一.服务器端操作重载

    1.接口本身支持重载

    interface ICalculator
     {
         int Add(int arg1, int arg2);
         double Add(double arg1, double arg2);
     }


    2.若将此接口作为服务契约,WSDL规定方法不可重载

    以下定义是错误的

    //Invalid contract definition:
     [ServiceContract]
     interface ICalculator
     {
         [OperationContract]
         int Add(int arg1, int arg2);
     
         [OperationContract]
         double Add(double arg1, double arg2);
     }

    3.可以用OperationContract的Name属性设置方法的别名

    [ServiceContract]
     interface ICalculator
     {
         [OperationContract(Name = "AddInt")]
         int Add(int arg1, int arg2);
     
         [OperationContract(Name = "AddDouble")]
         double Add(double arg1, double arg2);
     }

    这样客户端就会生成AddInt和AddDouble方法.客户端会生成如下代码

    [ServiceContract]
       interface ICalculator
       {
           [OperationContract]
           int AddInt(int arg1, int arg2);
     
           [OperationContract]
           double AddDouble(double arg1, double arg2);
       }
       class CalculatorClient : ClientBase<ICalculator>, ICalculator
       {
           public int AddInt(int arg1, int arg2)
           {
               return Channel.AddInt(arg1, arg2);
           }
           public double AddDouble(double arg1, double arg2)
           {
               return Channel.AddDouble(arg1, arg2);
           }
           //Rest of the proxy
       }


    最好是避免这种写法,直接修改方法名

    二.客户端操作重载

    也可以在客户端指定别名

    [ServiceContract]
       interface ICalculator
       {
           [OperationContract(Name = "AddInt")]
           int Add(int arg1, int arg2);
     
           [OperationContract(Name = "AddDouble")]
           double Add(double arg1, double arg2);
       }
     
       class CalculatorClient : ClientBase<ICalculator>, ICalculator
       {
           public int Add(int arg1, int arg2)
           {
               return Channel.Add(arg1, arg2);
           }
           public double Add(double arg1, double arg2)
           {
               return Channel.Add(arg1, arg2);
           }
           //Rest of the proxy
       }
  • 相关阅读:
    BDOC ROUTER
    web dom api中的Selection和Range
    基于第三方vuejs库组件做适配性个性开发
    香草js侦测元素是否离开视窗viewport
    xampp windows10下xdebug调试环境安装及配置
    beyond compare全文件夹比较,仅显示变化的文件
    给定制的vuejs组件添加v-model双向绑定支持
    javascript工厂函数(factory function)vs构造函数(constructor function)
    edrawmax使用技巧备忘
    babel plugin和presets是什么,怎么用?
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/1809589.html
Copyright © 2011-2022 走看看