Suggested Videos
Part 26 - What is a windows service
Part 27 - Hosting a wcf service in a windows service
Part 28 - Advantages and disadvantages of hosting a wcf service in a windows service
In this video we will discuss, hosting wcf service in IIS. This is continuation to Part 28. Please watch Part 28, before proceeding.
To host a wcf service in IIS, create a file with .svc extension. This file contains ServiceHost directive. The Service attribute of ServiceHost directive, specifies which service this file points to. The service code can reside in
1. The .svc file
2. A separate assembly
3. A file in App_Code folder
The configuration for the wcf service goes in web.config file.
The ServiceHost directive in .svc file is responsible for creating an instance of ServiceHost when required. There is no need to write code to instantiate and start ServiceHost, as we did with self hosting.
Here are the steps to host a wcf service in IIS
Step 1: Right click on HelloService solution in Solution Explorer and select Add - New Web Site. Fill in the details as shown in the image below.
Step 2: Delete IService.cs and Service.cs files that are present under App_Code folder.
Step 3: Add a reference to HelloService WCF library. To do this, right click on HelloService\HelloServiceIISHost project in Solution Explorer and select "Add Reference" option and add a reference to HelloService project.
Step 4: Rename Service.svc file to HelloService.svc. Copy and paste the following code in HelloService.svc file.
<%@ ServiceHost Language="C#" Debug="true" Service="HelloService.HelloService"%>
Step 5: Copy and paste the following code in web.config file
Step 6: Configure IIS
a) Open IIS. In the run window, type INETMGR and press enter key.
b) Expand Sites folder. Right click on "Default Web Site" and select "Add Application" option.
c) In "Add Application" make sure you have the following settings and click OK.
Alias = HelloService
Application pool = ASP.NET v4.0
Physical path = C:\HelloService\HelloServiceIISHost
Step 7: Navigate to http://localhost/HelloService/HelloService.svc. On this page you should have link to view the WCF service WSDL.
Step 8: Test if the service works as expected using a client application.
In our next video, we will discuss the advantages and disadvantages of hosting WCF service in IIS.
Part 26 - What is a windows service
Part 27 - Hosting a wcf service in a windows service
Part 28 - Advantages and disadvantages of hosting a wcf service in a windows service
In this video we will discuss, hosting wcf service in IIS. This is continuation to Part 28. Please watch Part 28, before proceeding.
To host a wcf service in IIS, create a file with .svc extension. This file contains ServiceHost directive. The Service attribute of ServiceHost directive, specifies which service this file points to. The service code can reside in
1. The .svc file
2. A separate assembly
3. A file in App_Code folder
The configuration for the wcf service goes in web.config file.
The ServiceHost directive in .svc file is responsible for creating an instance of ServiceHost when required. There is no need to write code to instantiate and start ServiceHost, as we did with self hosting.
Here are the steps to host a wcf service in IIS
Step 1: Right click on HelloService solution in Solution Explorer and select Add - New Web Site. Fill in the details as shown in the image below.
Step 2: Delete IService.cs and Service.cs files that are present under App_Code folder.
Step 3: Add a reference to HelloService WCF library. To do this, right click on HelloService\HelloServiceIISHost project in Solution Explorer and select "Add Reference" option and add a reference to HelloService project.
Step 4: Rename Service.svc file to HelloService.svc. Copy and paste the following code in HelloService.svc file.
<%@ ServiceHost Language="C#" Debug="true" Service="HelloService.HelloService"%>
Step 5: Copy and paste the following code in web.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior"
name="HelloService.HelloService">
<endpoint address="HelloService" binding="basicHttpBinding"
contract="HelloService.IHelloService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Step 6: Configure IIS
a) Open IIS. In the run window, type INETMGR and press enter key.
b) Expand Sites folder. Right click on "Default Web Site" and select "Add Application" option.
c) In "Add Application" make sure you have the following settings and click OK.
Alias = HelloService
Application pool = ASP.NET v4.0
Physical path = C:\HelloService\HelloServiceIISHost
Step 7: Navigate to http://localhost/HelloService/HelloService.svc. On this page you should have link to view the WCF service WSDL.
Step 8: Test if the service works as expected using a client application.
In our next video, we will discuss the advantages and disadvantages of hosting WCF service in IIS.