WCF Learning Journey-WCF Service deployment to IIS7.5 (ix)

Source: Internet
Author: User

Iv. WCF services deployed to IIS7.5

We host WCF on top of IIS, and the main advantage of hosting a service in IIS is that the host process is started automatically when a client request occurs, and you can rely on IIS to manage the life cycle of the host process. The process of developing and using is very similar to a Web service.

1) Create the. svc file for the WCF service

For every service that has an ASP. asmx file, the client implements a call to the corresponding WEB service by accessing the. asmx file. A WCF service is similar to a Web service, and each WCF service also has a corresponding file with a. svc file name extension. IIS-based service boarding requires that the corresponding WCF service have a corresponding. svc file, the. svc file is deployed in the IIS site, and the call to the WCF service is reflected on access to the. svc file.

The content of the. svc file is simple and contains only one ServiceHost instruction (Directive), which has a required service attribute and some optional properties. So the simplest. The SVC only has a ServiceHost directive that contains the service attribute, which indicates the valid type of the corresponding WCF service. Bookservice the corresponding. svc as shown below, we put the. svc in the root directory of the services project and name the file bookservice.svc.

<%@ ServiceHost language= "C #" debug= "true" service= " wcfservicelib.bookservice"%>2) Create a Web. config file for WCF
<?XML version= "1.0" encoding= "UTF-8"?><Configuration>    <system.webserver>        <Directorybrowseenabled= "true" />    </system.webserver>         <System.ServiceModel>    <Services>      <Servicename= "Wcfservicelib.bookservice">        <EndpointAddress=""binding= "BasicHttpBinding"Contract= "Wcfservicelib.ibookservice">        </Endpoint>      </Service>    </Services>    <Behaviors>      <servicebehaviors>        <Behavior>          <!--to avoid leaking metadata information, set the following values to false before deployment -          <Servicemetadatahttpgetenabled= "True"httpsgetenabled= "True" />          <!--to receive the fault exception details for debugging, set the following value to True. Set to false before deployment to avoid leaking exception information -          <ServicedebugIncludeexceptiondetailinfaults= "False" />        </Behavior>      </servicebehaviors>    </Behaviors>  </System.ServiceModel>    <system.web>        <compilationDefaultLanguage= "C #" />    </system.web></Configuration>

3) Place the above files and assemblies in the appropriate directory

Create a folder where the above files and assemblies are placed in the directory you want. Here, create the folder ' WCF ', put the file ' bookservice.svc ', ' web. config ' into.

Because a Web application will load the assembly from the bin directory at the root by default when it is running, the assembly ' WcfServiceLib.dll ' is placed under the subdirectory ' bin ', as in.

4) Create a website for the WCF service
    1. In IIS 7.5, on the Default Web Site, right-click on the shortcut menu and tap "Add Application ...".

2. In the Add Application dialog box, enter the contents in the aliases, physical path text boxes, and click the Select button to select "ASP. v4.0 Classic" in the pop-up "Select Application Pool".

3. Create a result after completion, such as.

4. Browse the Bookservice.svc page. Such as.

5. The final result, such as.

5) How to solve the problem in the boarding process

1. HTTP Error 404.3-not Foundthe page you requested could not be supplied due to an extended configuration issue. If the page is a script, add a handler. If you should download the file, add a MIME map. Such as.

Solution:

Here's how: Control Panel - All Panel Items - programs and Features - turn on or off Windows function -

2. Failed to "System.ServiceModel, version=3.0.0.0, Culture=neutral, publickeytoken=b77a5c561934e089" from the Assembly The type "System.ServiceModel.Activation.HttpModule" is loaded in c4> .

Description : An unhandled exception occurred during the execution of the current WEB request. Check the stack trace information For more information about the error and the source of the error in your code.

Exception Details : System.TypeLoadException: Failed from assembly "system.servicemodel,version=3.0.0.0, Culture=neutral, publickeytoken= b77a5c561934e089 "Load Type" System.ServiceModel.Activation.HttpModule ".

Such as.

Solution:

Execute the following instruction in the CMD command window. Aspnet_regiis.exe-i. Such as.

3. It is provided as a Service attribute value in the ServiceHost directive , or in the configuration element system.servicemodel/servicehostingenvironment available in/serviceactivations.

Solution:

open a. svc file and you will see <%@ ServiceHost language= "C #" debug= "true" service= "Wcfservicelib.bookservice " %> Note that the red font is consistent with the classes provided by WCF.

WCF Learning Journey-WCF Service deployment to IIS7.5 (ix)

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.