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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek