wcf中不存在方法重载,wcf的操作重载分为服务重载和客户端重载两种方式。

服务重载:通过OperationContractName属性重命名方法在客户端显示的名称.

wcf Code
[ServiceContract]
    public interface ICalculator
   {
        [OperationContract(Name = "AddInt")]
        int Add(int args1, int args2);

         [OperationContract(Name = "AddDouble")]
         double Add(double args1, double args2);
    }

客户端重载:添加服务引用的方式,自动生成文件 Reference.cs 文件,同样添加 name 属性.

 

wcf Code
System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ICalculator/AddInt", Name="AddInt" ,ReplyAction = "http://tempuri.org/ICalculator/AddIntResponse")]
       int Add(int args1, int args2);

        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/ICalculator/AddDouble",Name="AddDouble" ,ReplyAction = "http://tempuri.org/ICalculator/AddDoubleResponse")]
         double Add(double args1, double args2);

 

总结:

服务端重载的实际意义不大,因为不能在客户端调用的时候真正实现重载。

客户端的重载还有点实际作用,最起码方便客户端的方法调用功能,但是要实现客户端的重载相比直接添加服务引用,我们的工作量还是显著的增加,并且客户端重载还是记得要添加客户端接口OperationContractAttributeName属性的值。

 

 

Tks:http://www.cnblogs.com/jiagoushi/archive/2013/04/15/3023197.html

相关文章:

  • 2021-08-31
  • 2021-11-20
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-12-11
猜你喜欢
  • 2021-08-29
  • 2022-03-09
  • 2021-08-07
  • 2022-01-19
  • 2021-05-20
  • 2021-12-15
  • 2022-01-28
相关资源
相似解决方案