Host WCF service in iis – Easy WCF
Skip to content

Host WCF service in iis

To Host a WCF service in iis,we will make use of same WCFSelfHostService webservice that we have created.

To host WCF service in iis:

  • Right click on solution–>Add–>new website–>WCF service–>Save it in same folder where we have WCFSelfHostService and name it WCFIISHost.
  • Delete cs files from appcode folder because we wanted to host existing service
  • Add reference to WCFSelfHostService from solution
  • Rename service1.svc to WCFIISHost.svc
  • open WCFIISHost.svc file and remove the codebehind attribute because our code is not there.
  • CodeBehind=”~/App_Code/Service.cs”
  • give the fully qualified name of service i.e. Service=”WCFSelfHostService.WCFSelfHostService”
  • Specify the service end point url in web.config

In Run window, type inetmgr and it will open iis for you. expand root node and right click on default website and select Add application
Give an alias to the service and give the physical path and select application pool as ASP.net4.5
It will create the virtual directory for your service in iis. Then build solution
Then browse the service from inetmgr
Then you can test your client by adding service reference to wsdl document and test it
To host a wcf service in iis,you need to create a file with .svc extension.The service code can be present in .svc file or a separate assembly or in a file in App_code folder.The configuration for WCF service reside in web.config file.

Advantages of Hosting WCF service in iis:

No custom code is required to host the service
The servicehost directive in .svc file is responsible for creating an instance of Service host when required, so no need to write custom code for hosting
Automatic message based activation
We need not start/stop the service manually.iis provides message based activation.The service can be activated when a message arrives at the service, so it should not run all the time like self hosting

Automatic process recycling:

iis provides the capability for automatic process recycling if the process takes long time to serve the request. This is not there in self hosting.

Disadvantages of Hosting WCF service in iis:

Hosting wcf service in iis6.0 is limited to HTTP communication only.

© 2015, admin. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *