Steps to host a WCF service in IIS5.1(XP)

Krishna Kumar picture Krishna Kumar · Oct 31, 2009 · Viewed 10.9k times · Source

I have developed a sample WCF service. I would like to know the steps to host this in IIS 5.1(XP)

Answer

marc_s picture marc_s · Oct 31, 2009

1) You need a IIS virtual directory --> create it using IIS Manager

2) You need a *.svc file which references your service - it's a text file which must reside inside your virtual directory just created, and it would be something like:

<% @ServiceHost Service="YourNameSpace.YourServiceClass" 
                Language="C#" Debug="False" %>

That works if your WCF service class is in an assembly deployed to the "bin" directory below your virtual directory.

If you happen to have your actual service code in a "code-behind" file inside your "App_Code" directory (which I would not recommend), then you'd need this contents in your *.svc file:

<% @ServiceHost Service="YourServiceClass" 
                CodeBehind="~/App_Code/YourServiceClass.cs"
                Language="C#" Debug="False" %>

3) You need your config in web.config - you need at least the <service> tag plus possibly more depending on your needs:

<system.serviceModel>
   <services>
      <service name="YourNameSpace.YourServiceClass"
               behaviorConfiguration="MetadaTaEnabled">
         <endpoint address="" 
                   binding="wsHttpBinding" 
                   contract="YourNameSpace.IYourService" />
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MetadaTaEnabled">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

Here, you need to decide what binding (protocol) to use.

If you do all this, and everything was successful, you should be able to browse to your virtual directory URL with IE (http://yourserver/virtualdirectory/YourService.svc) and see the "landing page" of your service.

Marc