In my earlier article I discussed Exposing WCF REST Service over HTTPS. A major limitation of the service created in that article was it's self-hosted nature. In this article, I will continue with that service and host it in IIS. So at the end of this article, you will be able to host a WCF REST Service in IIS with HTTPS.
Configure IIS
To start with let us first configure a Web Site in IIS.
Open IIS
- Open the command prompt in administrator mode. To do that click on the Start button then type RUN in search and then in Run window type inetmgr to open IIS.
Now you will have IIS open like below:
- Right-click on Sites and then click Add Web Site
- Now a window will open.
Give any name of your choice as the site name. I am using the name HostedWcfService
Now click on select and choose ASP.Net v4.0 from the drop down.
Now in the physical path section, we need to give the 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 the Windows Explorer. Open the project in Windows Explorer and from the address bar copy the path and paste that below. Or you can browse to it. Just click on the browse button and navigate to the project folder of the WCF Service.
Now at the Binding section select HTTPS. Give any port number. I am leaving default port.
Again I am selecting DEBUGMODE certificate.
Note: the steps to create a certificate is in my previous article Exposing WCF REST Service over HTTPS
Configure WEB.Config
In the last article we created a self-hosted WCF REST Service. Now we need to host the service in IIS. So we need to configure EndPoint in Web.Config.
Open Web.Config of WCF Service
- Add service End Point
IService1 is Service Contract name and svcBehavior is service behavior. And of course for REST service we are using webHttpBinding.
- Create Service Behavior
- Add Transport level security to webHttpBinding
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
-
Choose Web Deploy
-
At Site URL give any URL of your choice
-
In Site Application give the name of the site you created in the beginning of this article.
In this article we saw how to host WCF REST Service in IIS with HTTPS. Thanks for reading. I hope it was useful.