WCF distributed development step by step for Win (5) service contract and Operation Overload

Source: Internet
Author: User

In the last section of WCF distributed development step-by-step for Win (4): WCF Service Reliability transmission configuration and programming development, this section we continue to learn WCF distributed development step-by-step for the win section (5): Service contract and Operation Overload. Here we first explain the method overload in OOP object-oriented programming, the meaning of overload, WCF service programming development How to implement the operation overload, then is the code analysis part, has given the service end service contract definition and realizes the operation overload the attention question and the realization process, then introduced the client to realize the operation overload the way in detail. Finally, the summary part of this paper. The structure of this section is: "1" Overload concept "2" Operation Overload "3" Code Implementation Analysis "4" Run Results "5" Summary

"1" Overload concept:

"1.1" What is Overload (overload):

Overload means that the same method name can correspond to the implementation of multiple methods. These methods have the same name, but the parameters of the method are of different types. This is the concept of method overloading. The application of function method classes and objects is particularly important.

Method overloading requires the compiler to uniquely determine which method code should be executed when a method is invoked, that is, which method is implemented. When determining the method implementation, the requirements are differentiated from the number and type of method parameters. That is, when you do a method overload, you require that the method of the same name be different on the number of arguments or on the parameter type. Otherwise, the overload will not be implemented.

On overloading it is important to note that the overloaded method must have a different parameter type and number of arguments (that is, either the type of the parameter is different or the number of arguments is different, or the type and number of arguments are different), otherwise the compiler will not know what to call that method.

The benefit of method overloading is the same method, with different results and implementations, where we can decide to invoke the Fly method based on the difference between passing parameters. This is an implementation mechanism of compile-time polymorphism.

"1.2" C # class method overload example:

Here we give a simple C # language implementation of the method overload, here for the Sayhellooverloading method, the same class given three methods of the number of parameters are different. Internal implementations are also different. The specific code is as follows:

//3.面向对象里的类,如何实现操作重载,和WCF服务类里的操作重载做对比
     public class ClassOverLoading
     {
         public ClassOverLoading()
         {

         }
         //掩饰方法重载,分别实现三个方法,C#等面向对象的语言提供了方法重载机制的支持。
         public string SayHelloOverLoading()
         {
             //编写代码
             return "Hello,This an C# class overloading demo";
         }
         //类里的方法重载不需要别名
         public string SayHelloOverLoading(string name)
         {
             //编写代码
             return "Hello:" + name + "This an C# class overloading demo";
         }

         public string SayHelloOverLoading(string firstName, string lastName)

         {
             //编写代码
             return "Hello:" + firstName + lastName + "This an C# class overloading demo";
         }

     }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.