Developing a WCF Service Library and Hosting it as WCF Web Service Using VS2K8 - Creating a Windows Communication Foundation (WCF) Service Library: application configuration
(Page 3 of 5 )
As we created a WCF Service Library (instead of a WCF Service Application), Visual Studio adds an "app.config" file (as opposed to a "web.config" as it would with a WCF Service Application) to the solution. Modify "app.config" to match the following:
<system.serviceModel>
<services>
<service name="WCFSampleService.EmpService" behaviorConfiguration="WCFSampleService.EmpServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost/EmpService" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WCFSampleService.IEmpService" />
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFSampleService.EmpServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="SampleServiceBinding">
<security/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
Turning a Windows Communication Foundation (WCF) Service Library into a WCF Service Application (web service)
In the previous section, we worked with "app.config" to configure the WCF Service Library. To turn a WCF service library into WCF service application (or WCF Web Service), the first step is to add "web.config" to the solution and make modifications to the file to match the following (look for the "added by me" comments):
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<WorkflowRuntime Name="WorkflowServiceContainer">
<Services>
<add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add type="System.Workflow.Runtime.Hosting.
DefaultWorkflowCommitWorkBatchService, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</Services>
</WorkflowRuntime>
<appSettings/>
<!-- added by me-->
<connectionStrings>
<add name="cnNorthwind" connectionString="Database=Northwind;Server=(local)sql2k5;user id=sa;password=eXpress2005"/>
</connectionStrings>
<!-- added by me -->
<system.serviceModel>
<services>
<service name="WCFSampleService.EmpService" behaviorConfiguration="WCFSampleService.EmpServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost/EmpService" />
</baseAddresses>
</host>
<endpoint address ="" binding="wsHttpBinding" contract="WCFSampleService.IEmpService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFSampleService.EmpServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="SampleServiceBinding">
<security/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<system.web>
<compilation debug="false"/>
<authentication mode="Windows"/>
<httpModules>
<add type="System.Workflow.Runtime.Hosting.WorkflowWebHostingModule, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="WorkflowHost"/>
</httpModules>
</system.web>
</configuration>
Once the "web.config" is added, the second step is to add an "EmpService.svc" file to the solution. Just add a text file (using "add new item") named "EmpService.svc" as shown below (fig 03).

Figure 03
Copy the following to "EmpService.svc."
<%@ ServiceHost Service="WCFSampleService.EmpService" %>
<%@ Assembly Name="WCFSampleService" %>
Once the service file is added, the final step is to change the "build output path" of the project to "bin" (as shown below in fig 04):

Figure 04
Close all tabbed windows of Visual Studio (I suspect it could be a bug as it could not compile properly on my machine, without closing all windows) and build the solution.
Next: Deploying and Hosting a WCF Service application (WCF web service) >>
More ASP.NET Articles
More By Jagadish Chaterjee