Windows Communication Foundation Overview

Source: Internet
Author: User
Tags call back

I hope that I can use several continuous blog posts to record the process of learning WCF, and share my experience in learning WCF with you.

It is difficult for people with poor English skills to learn the English documents of WCF. There are not many Chinese books, and two books are not easy to learn. They are also written like a graduate thesis.

Therefore, I want to write my own WCF article, hoping to promote my WCF knowledge and communicate with you to help you understand WCF.

Purpose: I will not use Chinese terminology (e.g. agreement, address, binding, channel, endpoint, host, ticket, duplex, callback, etc ), it is difficult to translate an English word into multiple Chinese words. I stick to the original English words (such as contract, address, binding, pipe, endpoint, host, one-way, duplicate, call back ).

I hate technical concepts most. It would be too painful to learn all the technologies if they were first fainted by a large number of technical terms. I have seen a book like this: When you open a page and find a read, you will find that you do not know what the author is talking about, because it is all difficult technical terms and concepts. In this case, people with poor English would rather read English documents. The technical teaching or communication I advocate is easy to understand. No matter how complicated new or old technologies are, they can be simply explained. It is not difficult to achieve this. I personally think that the author can simply use his own words. The more he copies the academic content, the more he seems to be authoritative, the lack of public affinity. After all, most people do not aim to write papers for the show, but to write their own real code. Haha. May the future of the IT industry be even better.

The book is back to the beginning.

========================================================== ====================================

It has been around for a long time, but for those who have just been in touch with WCF, there must be the following problems:

What is WCF? Why do we need WCF? What does WCF bring to us? What is the difficulty of learning WCF?

The answers to these questions have already been described on the Internet. I don't have to waste a bit of effort here, just to mention it.

WCF:Windows Communication Foundation. It can be seen from the name that this technology is closely related to communication. We know that software design is full of communication. Of course, after learning it, we can better know and use it, rather than simply trying to figure out its power from its name.

WCF provides us with a service-oriented (SOA) programming solution.: What is service-oriented? A friend who has used. NET web service development before can easily understand what service orientation is like .. NET Web Service is also a service-oriented solution proposed by Microsoft earlier. Service-oriented is a standard. Different companies can provide their own implementation frameworks. SOA is too abstract. After learning about a SOA implementation, such as. NET web service or WCF, I believe that you do not need any text definition, and you will also have a deep understanding of SOA. So what is service-oriented? I will not explain it here. You will have the answer yourself when you have been learning the WCF for a while. Really, haha.

WCF provides a Unified Communication Model: In the past, we wrote communication methods such as TCP, UDP, and socket, which were unified in WCF. As for how to unify? I will not talk about it here. Therefore, when you use multiple communication methods in the project at the same time, you can consider using WCF.

It is not difficult to accept WCF before I have been familiar with Web service development.Believe me!

This time, we will only give a brief introduction to the concept of WCF. More detailed knowledge will be provided later. Learn and communicate.

1. Open vs 2010 --> file --> new project, select WCF under C #, and select WCF library. For example:

2. Now the iservice file and a service file are available. Two Functions in iservice implemented by the service file: getdata function and getdatausingdatacontract function. What are the two functions? Not to mention what everyone can understand. Then describe their roles in detail. The class name and function name are not modified here.

3. Press F5 to run the program. A test window of WCF is opened. For example, test the getdata function first.

Test results:

Test the getdatausingdatacontract function in the same way: The result is as follows:

4. The above has completed a simple test of the functions of the WCF function. It can be noted that the service correctly implements iservice. Next we need to deploy this WCF to a Web site.

In the solution, right-click: New --> new web site, for example:

Modify the service = "wcffirstdemoservicelib. service1" in the service. SVC file of the Web site project (the service name is specified by namespace and class name)

 

5. Add a winform program to call the WCF function.

6. Add a web reference to the winform project:

7. add several controls on form1, and then add the following lines of code in form1.cs:

Form1.cs

 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using WCFClient.WCFServiceDemo;10 11 namespace WCFClient12 {13     public partial class Form1 : Form14     {15         Service1Client proxy = null;16         CompositeType ctin = null;17         CompositeType ctout = null;18         public Form1()19         {20             InitializeComponent();21         }22 23         private void btnGetData_Click(object sender, EventArgs e)24         {25             this.tbOutputBox.Text = proxy.GetData(Convert.ToInt32(this.tbInputbox.Text));26         }27 28         private void Form1_Load(object sender, EventArgs e)29         {30             proxy = new Service1Client();31 32         }33 34         private void button2_Click(object sender, EventArgs e)35         {36             ctin = new CompositeType();37             ctin.StringValue = this.tbInputCTStrvalue.Text;38             ctin.BoolValue = this.rboxInTrue.Checked;39             40             ctout = proxy.GetDataUsingDataContract(ctin);41 42             this.tbOutputCTStrvalue.Text = ctout.StringValue;43             if (ctout.BoolValue)44             {45                 this.rboxOutTrue.Checked = true;46             }47             else48             {49                 this.rboxOutFalse.Checked = true;50             }51         52         }53     }54 }

8. Run Ctrl + F5:

 

Note: Here is only an overview of WCF. Therefore, the default settings of WCF are all used, and the roles of each step are not described in detail. Only three projects are provided: Project 1 is the Library of WCF and also the core function of WCF. Project 2 is the host of WCF used to publish the interface provided by WCF to the outside world (Note: Indicates which functions can be called ). Project 3 is the client for calling WCF. In fact, the concept of a distributed software architecture has been highlighted here: there are modules dedicated to providing function implementation, modules dedicated to providing open interfaces, and modules dedicated to calling.

The following details each part of the WCF. Welcome !!

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.