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.
To start with let us first configure a Web Site in 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.
Now you will have IIS open like below
b. Right click on Sites and then click Add Web Site
c. Now a window will open.
Give any name of your choice as the site name. I am giving name here 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 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.
Now at the Binding section select HTTPS. Give any port number. I am leaving default port.
Again I am selecting DEBUGMODE certificate.
Note: steps to create certificate is in my previous post Exposing WCF REST Service over HTTPS
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
IService1 is Service Contract name and svcBehavior is service behavior. And of course for REST service we are using webHttpBinding.
2. Create Service Behavior
3. 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>
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.
In this post we saw how to host WCF REST Service in IIS with HTTPS. Thanks for reading. I hope it was useful.