WCF (5) host WCF Service

Source: Internet
Author: User

This time we will discuss host a WCF Service.

Aforementioned

In order for the client to use the service, we must host the service to a runtime environment (we call it Host application), because it is always waiting for a request from the client ). someone translates the host into "host", and I still use host. host application is responsible for start and endservice, then listens for requests from the client, parses the request from the client, and then calls the corresponding service. finally, return the result to the client.

 

The Host application creates a servicehost object for each service. when multiple services exist, multiple servicehost objects are created. when the client needs to use multiple protocols (communication protocols), such as HTTP and TCP, you do not need to create multiple services, because we know that a service can have multiple endpoints (endpoints include addresses, binding, contract ). binding specifies different protocols. Therefore, you only need to create multiple endpoints and specify different protocols in binding.

You can import the service host to the following environment::

1. IIS: we need to create a web site, use this website to go to host WCF, and then put this website in IIS. if you use IIS to go to host WCF, you can only use HTTP protocol. when a request arrives, the host application can be automatically activated and started to listen.

2. was :( Windows Process activation service) is a new feature of iis7.0. we also need to create a web site. was can be installed on Vista, Windows 7, Windows server2008, and other operating systems. if you use was to host WCF, you can use HTTP, TCP, MSMQ, named pipe protocol. when a request arrives, the host application can be automatically activated and started to listen.

3. Managed Application (managedProgram, Such as console, winfrom, WPF): Self-hosting. When a request arrives, the host application cannot be automatically activated.CodeManually new the servicehost object.

How do we choose which host method??

The answer is: It depends on your operating system, communication requirements, and specific scenarios.

1. if your operating system is Windows server2003, and the program only uses http to meet your needs. use IIS to go to host. if the program does not meet the requirements in addition to HTTP (in addition to HTTP, TCP is also required), you need to create the window service to go to the host.

2. If your operating system is Windows server2008 (or Windows 7), use was because it supports more protocols.

3. If it is only used for demonstration, you can use the console to go to the Host. However, it is best to use winform or WPF when release to a real product.

How can we implement each method?

Unfinished, To be continued ....

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.