Developing a WCF Service Library and Hosting it with a Custom App Using VS2K8 - Creating a WCF Service Library
(Page 2 of 5 )
The following are the steps required to create a WCF Service Library:
Open Microsoft Visual Studio 2008 Beta 2
Go to File || New Project
In the "New Project" dialog box, open "Visual Basic" project types and select WCF. The respective templates for WCF will be shown on the right side.
Select the "WCF Service Library" template.
Provide "WCFSampleService" as the name and provide the proper path as the location.
Make sure that ".NET Framework 3.5" is selected at the top.
Once everything looks like the following (fig 01), click OK.
Rename "IService1.vb" to "IProductService.vb."
Rename "Service1.vb" to "ProductService.vb."

Creating a WCF Service Library: application configuration
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" file in a WCF Service Application) to the solution. Modify the "app.config" file to match the following:
<system.serviceModel>
<services>
<service name="NorthwindService.ProductService"
behaviorConfiguration="NorthwindService.ProductServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8181/ProductService" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied
above -->
<endpoint address="" binding="wsHttpBinding"
contract="NorthwindService.IProductService" />
<!-- 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="NorthwindService.ProductServiceBehavior">
<!-- 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>
</system.serviceModel>
Now it is time to specify the connection string. Using Solution Explorer, right click on project and go to properties (Fig 02):

Within the project properties, open the Settings tab and add a new setting with the name "cnNorthwind," "Type" as "String", "Scope" as "Application" and "Value" as required connection string (to connect to database) as shown below (Fig 03):

Next: Creating a WCF Service Library: source code >>
More ASP.NET Articles
More By Jagadish Chaterjee