Friday, 1 January 2016

Is overloading possible in WCF? If yes then how?




     Yes, by using [OperationContract(Name="OverloadedName")] But, still outer world will get them with unique and different name. Overloading is a technique to write manageable/maintainable code. But in case of WCF service, uniqueness is required for generating WSDL, and that can be done either by using unique method name or unique OperationContract's name attribute value. Interfaces plays an important role and provides much flexibility for this. We can write many implementations of an interface, and it gives more flexibility plus concise. So why to think on overloading for WCF service methods?
    
    Example  :-
                 
   [OperationContract(Name="AddInt")]
       public int Add(int a, int b)
       {
          return a+b;
          }
      

   [OperationContract(Name="AddDouble")]
       public double Add(double a, double b)
       {
          return a+b;
          }

      Note:- here we have overlaoded the methods but these are still unique by name for outer world.



     In the above post I explained how overloading can be done in WCF. I hope you enjoyed this post so please comment your feedback and queries. Thanks You.


 



No comments:

Post a Comment