Hosting WCF REST Service in IIS with HTTPS

In earlier post I discussed Exposing WCF REST Service over HTTPS. Major limitation on service created in last post was its self-hosted nature. In this post, I will take same service forward and host in IIS. So at the end of this post, you would able to host WCF REST Service in IIS with HTTPS.

Configure IIS

To start with let us first configure a Web Site in IIS

Open IIS

a. Open the command prompt in administrator mode. To do click on Start button then type RUN in search and then in Run window type inetmgr to open IIS.

clip_image001

Now you will have IIS open like below

clip_image003

b. Right click on Sites and then click Add Web Site

clip_image004

c. Now a window will open.

clip_image005

Give any name of your choice as the site name. I am giving name here HostedWcfService

clip_image006

Now click on select and choose ASP.Net v4.0 from the drop down.

clip_image007

Now in the physical path section, we need to give physical path of the service. So to get the physical path of the service, right click on the WCF Service project in visual studio and click open project in windows explorer. Open the project in windows explorer and from address bar copy the path and paste that below. Or you can browse also. Just click on browse button and navigate to project folder of the WCF Service.

clip_image008

Now at the Binding section select HTTPS. Give any port number. I am leaving default port.

clip_image009

Again I am selecting DEBUGMODE certificate.

Note: steps to create certificate is in my previous post Exposing WCF REST Service over HTTPS

Configure WEB.Config

In last post we created a self-hosted WCF REST Service. Now we need to host service in IIS. So we need to configure EndPoint in Web.Config.

Open Web.Config of WCF Service

1. Add service End Point

clip_image011

IService1 is Service Contract name and svcBehavior is service behavior. And of course for REST service we are using webHttpBinding.

2. Create Service Behavior

clip_image013

3. Add Transport level security to webHttpBinding

clip_image014

WEB.Config will look like


<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="svcBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding>
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="WcfService13.IService1" behaviorConfiguration="svcBehavior">
<endpoint name="" binding="webHttpBinding" address="" contract="WcfService13.IService1" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

Publish Service

Right click on WCF Service and click on Publish

1. Choose Web Deploy

2. At Site URL give any URL of your choice

3. In Site Application give name of site you created in beginning of this post.

clip_image015

In this post we saw how to host WCF REST Service in IIS with HTTPS. Thanks for reading. I hope it was useful.

4 responses to “Hosting WCF REST Service in IIS with HTTPS”

  1. thank Dhananjay for this post, it works fine for me.

    Next question: How can I use basic aunthentication with https in iis

  2. […] Hosting WCF REST Service in IIS with HTTPS […]

  3. […] Hosting WCF REST Service in IIS with HTTPS. […]

  4. […] Hosting WCF REST Service in IIS with … – thank Dhananjay for this post, it works fine for me. Next question: How can I use basic aunthentication with https in iis […]

Leave a comment

Create a website or blog at WordPress.com