Deploy the WCF Service hosted in Internet Information Service

Source: Internet
Author: User
Tags http authentication http digest authentication processing instruction msmq
Deploy the WCF Service hosted in Internet Information Service

The development and deployment of Windows Communication Foundation (WCF) Services hosted by Internet Information Service (IIS) include the following tasks:

    • Make sure that you have correctly installed and registered IIS, WCF, and WCF activation components.
    • Create a new Iis ApplicationProgram, Or re-use the existing ASP. NET application.
    • Create a. SVC file for the WCF Service.
    • Deploy the service implementation to the IIS application.
    • Configure the WCF Service.

For detailed rehearsals on creating a WCF Service that is hosted in IIS, seeHow to: host the WCF Service in IIS.

Make sure that IIS and WCF are correctly installed and registered

You must install both WCF and IIS to run the WCF Service in IIS. The process of installing WCF (as part of. NET Framework 3.0) and IIS varies with the operating system version used. For more information about how to install WCF and. NET Framework 3.0, seeMicrosoft. NET Framework 3.0 reusable package(It may be an English webpage ). For instructions on IIS installation, seeInstall IIS(May be an English webpage.

If IIS already exists on the computer, you can register WCF with IIS when installing. NET Framework 3.0. If IIS is installed after. NET Framework 3.0 is installed, perform other steps to register WCF with IIS and ASP. NET. You can perform the following operations based on your operating system:

    • Windows XP SP2 and Windows Server 2003: Use servicemodelreg.exe to register WCF with IIS: to use this tool, TypeServicemodelreg.exe/I/x.
    • Windows Vista: Install the Windows Communication Foundation activation components sub-component of. NET Framework 3.0. To do this, in the control panel, click"Add or delete programs"And then click"Add/delete Windows Components". This will activate"Windows component wizard".
Create a new IIS application or reuse an existing ASP. NET application

The WCF Service hosted in IIS must reside in the IIS application. You can create a new IIS application to host the WCF Service. Alternatively, you can deploy the WCF Service to an existing application that has the content of ASP. NET 2.0 (such as the. ASPX page and ASP. NET web service [asmx. For more information about these options, seeWCF Service and ASP. NETIn section 2, "bearer WCF and ASP. NET in parallel" and "bearer WCF Service in ASP. NET compatibility mode.

Note that IIS 6.0 and later regularly restart independent object-oriented programming applications. Default Value: 1740 minutes. The maximum supported values are 71,582 minutes. You can disable this restart. For more information about this attribute, seePeriodicrestarttime(It may be an English webpage ).

Create a. SVC file for the WCF Service

The WCF Service hosted in IIS is represented as a special content file (. SVC file) in the IIS application ). This model is similar to the expression of the asmx page as a. asmx file in an IIS application .. The SVC file contains a specific WCF Processing Instruction (@ Servicehost.. The most common syntax of SVC files is shown in the following statement.

Copy code
 
<% @ Servicehost service = "mynamespace. myserviceimplementationtypename" %>

It consists@ ServicehostCommand and single attributeService.ServiceThe attribute value is the name of the Common Language Runtime Library (CLR) type implemented by the Service. Use this command with the followingCodeCreating a service host is basically equivalent.

Copy code
 
New servicehost (typeof (mynamespace. myserviceimplementationtypename ));

You can also perform other bearer configurations, such as creating a service base address list. You can also use customServicehostfactoryExtended commands are used to customize bearer solutions. IIS applications that carry the WCF Service are not responsible for management.ServicehostInstance creation and storage period. When you receive the first request for the. SVC file, the requiredServicehostInstance. When the Code explicitly closes the instance or recycles the application, the instance is not released.

For more information about the. SVC File Syntax, see@ Servicehost.

Deploy services to IIS applications

The WCF Service in IIS and ASP. NET 2.0 use the same dynamic compiling model. As in ASP. NET, you can deploy the implementation code of the WCF Service in IIS in several ways in various locations, as shown below:

    • As a pre-compiled. dll file in the Global Assembly Cache (GAC) or the \ bin directory of the application. The pre-compiled binary file is updated only after the new version of the class library is deployed.
    • As the uncompiled source file in the \ app_code directory of the application. When processing the first request of an application, the source files dynamically need to be located in this directory. Any changes made to the files in the \ app_code directory result in recycling and re-compiling the entire application upon receiving the next request.
    • As uncompiled Code directly placed in the. SVC file. The implementation code can also be placed in the. SVC file of the service in an inline manner, and after the @ servicehost command. Any changes made to the Inline code cause the application to be reclaimed and re-compiled upon receiving the next request.

For more information about ASP. NET 2.0 Compiling models, seeASP. NET compilation Overview(It may be an English webpage ).

Configure the WCF Service

The WCF Service in IIS stores the configuration in the web. config file of the application. The Services hosted in IIS use the same configuration elements and syntax as the WCF Services hosted outside of IIS. However, the following constraints are unique to the IIS bearer environment:

    • The base address of the Service in IIS.
    • By passing a set of base address URIsServicehostThe constructor can also provide<Host>Elements. Applications that host the WCF Service outside IIS can control the base addresses of these services. Services hosted in IIS cannot control their base addresses. The base addresses of Services hosted in IIS are the addresses of their. SVC files.
Endpoint address of the Service hosted in IIS

When it is hosted in IIS, any endpoint address is always considered as the address relative to the. SVC file that represents the service. For example, if the base address of the WCF Service is http: // localhost/application1/myservice. SVC that contains the following endpoint configuration.

Copy code
 
<Endpoint address = "anotherendpoint "... />

This provides an endpoint that can be accessed on "http: // localhost/application1/myservice. svc/anotherendpoint.

Similarly, an empty string is used as the end point configuration element of the relative address to provide an end point that can be accessed at http: // localhost/application1/myservice. SVC (which is the base address.

Copy code
<Endpoint address = ""... />

The relative endpoint address must always be used for Endpoints of Services hosted in IIS. If the endpoint address does not point to the IIS application that hosts the service of the public endpoint, a fully qualified endpoint address (for example, http: // localhost/myservice) is provided. SVC) may cause errors during service deployment. Use the relative endpoint address of the Service to avoid these potential conflicts.

Transfer available

The WCF Service hosted in IIS 5.1 and IIS 6.0 is restricted to HTTP-based communication. On these IIS platforms, configuring the services that are hosted to use non-HTTP binding will cause errors during service activation. For IIS 7.0, the supported transmission methods include HTTP, net. TCP, net. Pipe, net. MSMQ, and MSMQ. formatname for backward compatibility with existing MSMQ applications.

HTTP Transmission Security

The WCF Service hosted in IIS can use HTTP Transmission security (such as HTTPS and HTTP authentication schemes, such as basic, digest, and Windows integrated authentication ), the premise is that the IIS virtual directory containing the Service supports these settings. The HTTP transport security settings on the bound end point must match the transport security settings on the IIS virtual directory that contains it.

For example, a WCF endpoint configured to use HTTP digest authentication must reside in an IIS virtual directory that is also configured to allow HTTP digest authentication. If the combination of IIS settings and WCF endpoint settings does not match, an error occurs during service activation.

 

Transferred from msdn

Related Article

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.