Previously we discussed ways to Create a simple WCF library.  We’ll now explore ways to host that WCF library we had created, in IIS and just like before we’ll do it in simple steps.

Step 1: Create a website with the WCF Service template.  Be sure to avoid creating the website under My Documents, otherwise you’ll have to explicitly assign some permissions and we’ll avoid it for our discussions.  We’ll name this website, RegistrationServiceIisHost.  you should have the following files in the project:

Step 2: Delete the files IService.cs and Service.cs and add a reference (not a service reference) to the WCF library, we previously created.

Step 3:  Appropriately rename the Service.svc file, we’ll change it to RegistrationService.svc.  Open the file and modify the following:

  1. Remove the CodeBehind attribute
  2. Change the Service attribute value from Service to the fully qualified name of the concrete class in our WCF library, e.g.,  RegistrationServiceLib.RegistrationService

Step 4: Open the Web.config file and modify the following:

  1. Change the value of the name attribute of the first service node from Service to the fully qualified name of the concrete class in our WCF library, e.g.,  RegistrationServiceLib.RegistrationService
  2. Change the value of the same service node’s child endpoint node’s contract attribute value from IService to the fully qualified name of the service interface in our WCF library, e.g., RegistrationServiceLib.IRegistrationService.

Sample of changes to the Web.config file:

<system.serviceModel>
  <services>
    <service name="Service" "RegistrationServiceLib.RegistrationService" behaviorConfiguration="ServiceBehavior">
      <!– Service Endpoints –>
      <endpoint address="" binding="wsHttpBinding" contract="IService" "RegistrationServiceLib.IRegistrationService">

Step 5: Set the RegistrationService.svc file as the startup page via the context menu and run the project or browse to it in a browser and you should see auto generated service information page.

Step 6: Test the service by running the test client as we did in the last blog on the subject, e.g., running the WcfTestClient utility and feeding it the service URI.

Step 7: Publish the website to IIS

  1. Select the IIS Manager’s Default Web Site’s Add Application context menu
  2. Set the Alias to RegistrationServiceIisHost
  3. Set the Application pool to the appropriate ASP.NET framework version if other than the default
  4. Set the Physical path appropriately
  5. Browse to the RegistrationService.svc file

You now have a WCF service hosted in IIS.

In the next sequel, we’ll create a WPF client and consume this WCF service.