ASP.NET
  Home arrow ASP.NET arrow Page 4 - 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 with a Custom App Using VS2K8
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2007-10-02

    Table of Contents:
  • Developing a WCF Service Library and Hosting it with a Custom App Using VS2K8
  • Creating a WCF Service Library
  • Creating a WCF Service Library: source code
  • Build the project
  • Testing the WCF custom hosted Service: source code

  • 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 with a Custom App Using VS2K8 - Build the project


    (Page 4 of 5 )

    Developing a custom application to host the WCF: creation and configuration

    To host the previous WCF Service Library, I want my own custom application to be developed using Windows Forms. The following is the walk through:

    • Go to File || Add || New Project.

    • Select "Windows Forms Application" as template, provide "Name" as "NorthwindServiceHost" at the same solution location as shown below (Fig 04).

    • Design the form with two buttons (for Start and Stop service) and a label (for messaging).

    • Add an "app.config" file using "Add new Item" as shown below (Fig 05).

    • Copy the same <system.serviceModel> element from the previous "App.Config" (of the "NorthwindService" project) into the current one.

    • 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 in previous sections.

    • Add a reference to "NorthwindService" project (fig 06, fig 07).

    • Add a reference to "System.ServiceModel" (fig 08).

    Figure 04

    Figure 05

    Figure 06

    Figure 07

    Figure 08

    Developing a custom application to host the WCF: coding and testing

    The following is the source code for both the "Start" and "Stop" buttons designed in previous section:

    Imports System

    Imports System.ServiceModel

    Public Class Form1

    Dim host As ServiceHost

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnStart.Click

      host = New ServiceHost(GetType(NorthwindService.ProductService))

       host.Open()

        Me.lblMsg.Text = "Started"

    End Sub

    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnStop.Click

      host.Close()

       Me.lblMsg.Text = "Stopped"

    End Sub

    End Class

    Set the "NorthwindServiceHost" as the startup project as shown below (Fig 09).

    Execute the application and hit the "Start" button. It should start the service as follows (Fig 10). Always stop the service before closing the application.

    Go to the "bin" folder of "NorthwindServiceHost" and execute the "NorthwindServiceHost.exe" independently (without using Visual Studio). It should respond without any difference as shown in the following image (Fig 11).

    Testing the WCF custom hosted Service: creating the WCF Client using Windows Forms

    To test the WCF service hosted in previous sections, we need to develop a WCF client. In this case, for simplicity, I would like to work with Windows Forms.

    Add a new project (to the existing solution), select "Windows Forms Application" as the template, provide the name "NorthwindClient" and hit on OK.

    If not already started, start the service independently from Windows Explorer (as shown in the previous section).

    Add a service reference by right clicking on the "NorthwindClient" project and selecting "Add Service Reference" (fig 12).

    In the "Address" field, type http://localhost:8181/ProductService and hit GO. Before you hit GO, make sure that the service is already started independently (outside Visual Studio) as shown in previous section.

    Once the service is found, provide the namespace as "ProductService" and click OK (Fig 13).

    Design a form that looks like the following (Fig 14):

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hi,This is my second article focusing on developing WCF Services. This...
     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - 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

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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