How to Host a WCF service in IIS

Posted: October 14, 2014 in All, WCF
Tags: , , ,

In this article I would like to discuss on hosting a WCF service in IIS.

Create a WCF service application:

As a first step, create a  WCF service application.   From Visual Studio, go to File -> New -> Project.  Select ‘WCF Service Application’ under WCF in templates window.

The following components will be present in the newly created project:

  •         App_Data folder
  •         IService1.cs interface
  •         Service1.sbc and Service1.svc.cs files.  You can rename the interface and service files.
  •         Web.config file.

The Service1 class is defined with following two service methods and I don’t make any changes rather I would use it as it is.

  •         GetData
  •         GetDataUsingDataContract

Now we need to add end points for the service.  Go to web.config file and add following configuration under System.ServiceModel section.  Replace Contract and Service names according to your service namespace and class names.

<pre><system.serviceModel>
	<services>
  	<service name="MyTestService.Service1" >
    	<endpoint address="" binding="basicHttpBinding" contract="MyTestService.IService1">
    	</endpoint>
    	<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  	</service>
    </services>
…

 

Host WCF service in IIS:

Run inetmgr command from Start -> Run to open IIS.
Right click on Sites and select Add Website. Enter Site name.

Service

Note: When you add a new Website, by default it creates a new application pool. You may assign it to an existing pool. The newly created pool may be configured with .Net V2.0. So go to Application Pools in IIS and double-click on newly created application pool. If it is pointing to older .Net versions then select appropriate framework version (in our case, the web application is created with .net V4.0 in first step).
Now try to access the service and we should be able to access service metadata. The URL should be similar to following:
http://localhost/Service1.svc

We can use WCF Test Client tool to test your service.

Advertisements
Comments
  1. […] How to Host a WCF service in IIS […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s