Visual Studio.NET - WCF Hosting in IIS
Here is the step by step instructions for hosting WCF service in IIS.
WCF Hosting in IIS - Step By Step Instructions
- Create a "WCF Service Application" under VS2010
- Do a refactor to change the service name and implement desired methods.
- The files needed to host WCF service on IIS are given below:
- The configuration of web.config file is discussed in the next section.
- Create a virtual directory under IIS and make it as an application root. otherwise you would not be able to use the web config defined under this virtual directory.
- Copy the 3 files given on the step 3 into the virtual directory.
- Then you can access the .SVC wcf service using any IE.
- You can click the following link to invoke the WCF service which is given in my sample.
web.config file configuration
- Under services, you can have a collection of services.
- For each service, you can have the service name and multiple endpoints.
- For end point configuration: you need Address, Binding and Contract. You can remember with ABC for address, binding and contract
- The contract IMetadataExchange with address mex and binding type mexHttpBinding contains the meta data information and is used to expose the list of other services.
- If you want to disable meta data, then add the service behaviorconfiguration with <serviceMetadata httpGetEnabled="false"/>
- multipleSiteBindingsEnabled should be set to true under serviceHostingEnvironment to enable multiple bindings in each end points.
- The ServiceActivations settings will have the relative address of the .SVC file from the virtual directory application root and the service name.
- The following is the sample web.config file used to host WCF service in http://www.softwareandfinance.com/wcftestservice/TestService.svc
<compilation debug="true" targetFramework="4.0" />
<service name="Wcf_Test_Service.TestService" behaviorConfiguration="MyServiceTypeBehaviors">
<add relativeAddress="TestService.svc" service="Wcf_Test_Service.TestService"/>