Course from scratch WCF 4 (bearer service)

Source: Internet
Author: User

There is a picture of the truth. If you are a cainiao, let's take a look at the implementation of this cainiao step by step.

We all know that WCF must provide its own host to carry the service during running. Since the WCF itself does not have a host, we need to attach ourselves to the host to host the WCF Service.

How many methods can be used to provide us with the WCF bearer?

1. Load in IIS

2. Host in Windows Process activation Service (was)

3. hosted applicationsProgramMedium (self-bearing)

The first type is carried in IIS

WCF can be easily carried through IIS. This bearer model is similar to that used by ASP. NET and ASP. NET web services.

You can use IIS to host WCF on the following operating systems

-- IIS 5.1 on Windows XP SP2

-- Iis6.0 on Windows Server 2003

-- IIS 7.0 on Windows Vista (Windows 7) and Windows Server

-- IIS 7.0

-- Use Windows Process activation Service (was) to allow activation or network communication through protocols other than HTTP. This environment is suitable for developing a WCF Service that can communicate with any network protocol (HTTP, net. TCP, net. pipe, and net. MSMQ) supported by WCF.

-- Benefits of IIS

-You can deploy and manage the WCF Services hosted in IIS just like handling any other types of IIS applications (including ASP. NET applications and asmx.

-IIS provides process activation, running status management, and recovery functions to improve the reliability of the hosted applications.

-Like ASP. NET, the WCF Service hosted in ASP. NET can use ASP. NET to share the host model. In the secondary model, multiple applications reside in a common auxiliary process to increase server density and scalability.

-The same dynamic compilation model is used for the WCF Service in IIS and ASP. net2.0. This model simplifies the development and deployment of the service.

-When deciding to host the WCF Service in IIS, remember that iis5.1 and iis6.0 are only for HTTP Communication.

 

-- Deploy the IIS-hosted WCF Service

-1. Ensure that IIS, WCF, and WCF are correctly installed.

You can enable or disable windows in Control Panel-Program-program function

The environment is ready. Next let's take a look at the instance. First, we open vs. Here we use vs2010, and we will use vs2010 for the time being.

First open vs2010 to create a project,

Select the WCF Service Application and add the project name. The corresponding file is automatically generated.

 
In the iservice1.cs, service1.svc, and service1.cs filesCodeMerge into service. SVC in a file

<% @ Servicehost Language = "C #" DEBUG = "true" service = "wcfiisservice. service "%> using system; using system. runtime. serialization; using system. servicemodel; using system. servicemodel. web; using system. text; namespace wcfiisservice {// Note: use the "RENAME" command on the "refactoring" menu to change the class name "service1" in the code, SVC, and configuration file at the same time ". Public class service: iservice {Public String getdata (INT value) {return string. format ("You entered: {0}", value) ;}} [servicecontract] public interface iservice {[operationcontract] string getdata (INT value); // todo: add your service operation here }}

Open the Web. config file and find the node system. servicemodel. You can find that there should be no services node, that is, we need to configure the service.

<Services>
<Service name = "wcfiisservice. Service" behaviorconfiguration = "wcfbehavior">
<Endpoint address = "" binding = "wshttpbinding" Contract = "wcfiisservice. iservice"> </Endpoint>
<Endpoint address = "mex" binding = "mexhttpbinding" Contract = "imetadataexchange"> </Endpoint>
</Service>
</Services>

The code for the configuration file is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <system. web> <compilation DEBUG = "true" targetframework = "4.0"/> </system. web> <system. servicemodel> <services> <service name = "wcfiisservice. service "behaviorconfiguration =" wcfbehavior "> <endpoint address =" "binding =" wshttpbinding "Contract =" wcfiisservice. iservice "> </Endpoint> <endpoint address =" mex "binding =" mexhttpbinding "Contract =" imetadataexchange "> </Endpoint> </service> </servi CES> <behaviors> <servicebehaviors> <behavior name = "wcfbehavior"> <! -- To avoid metadata leakage, set the following value to false before deployment and delete the above metadata endpoint --> <servicemetadata httpgetenabled = "true"/> <! -- To receive fault exception details for debugging, set the following value to true. Set false before deployment to avoid leakage of exception information --> <servicedebug features = "false"/> </behavior> </servicebehaviors> </behaviors> <servicehostingenvironment multiplesitebindingsenabled = "true ""/> </system. servicemodel> <system. webserver> <modules runallmanagedmodulesforallrequests = "true"/> </system. webserver> </configuration>

 

After the corresponding configuration, compile the project, view the folder where the project is located, and find the Web. config file and service1.svc file.

Open IIS and add an application

After adding the file, copy the two files web. confg and service. SVC to the following directory.

Open Directory Browsing and right-click Enable. Now you can browse the service.

Now we can prove that the service has been released successfully.

This is the sample code for IIS to host the WCF Service.

About

In Windows Process activation Service (was), the host will be followed

 

 

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.