ASP.NET
  Home arrow ASP.NET arrow Page 3 - Developing a WCF Service Library and Hosti...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Developing a WCF Service Library and Hosting it as WCF Web Service Using VS2K8
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2007-10-01

    Table of Contents:
  • Developing a WCF Service Library and Hosting it as WCF Web Service Using VS2K8
  • Creating a Windows Communication Foundation (WCF) Service Library
  • Creating a Windows Communication Foundation (WCF) Service Library: application configuration
  • Deploying and Hosting a WCF Service application (WCF web service)
  • Testing the WCF Web Service: creating the WCF Client using Windows Forms

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,This is my first part for the series of articles on WCF. This...
       · Hello,I created a WCF service in VS2008 and when I try to browse the service in...
       · Great article! I just start doing this and learned quite a lot. I have one...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT