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:
- ApplicationRoot\TestService.svc
- ApplicationRoot\web.config
- ApplicationRoot\bin\TestService.dll
- 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.
http://www.softwareandfinance.com/wcftestservice/TestService.svc
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
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Wcf_Test_Service.TestService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address=""
binding="basicHttpBinding"
contract="Wcf_Test_Service.ITestService" >
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="TestService.svc" service="Wcf_Test_Service.TestService"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
|