ASP.NET
  Home arrow ASP.NET arrow Page 2 - 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


    (Page 2 of 5 )

    The following are the steps necessary 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 "IEmpService.vb."
    • Rename "Service1.vb" to "EmpService.vb."
    • Add a reference to "System.Configuration" as shown below (fig 02).

     

    Figure 01

    Figure 02

    Creating a Windows Communication Foundation (WCF) Service Library: source code

    Once the project is created (as shown above), modify "IEmpService.vb" to match the following:

     <ServiceContract()> _

      Public Interface IEmpService

    <OperationContract()> _

      Function GetNames() As List(Of String)

    <OperationContract()> _

      Function GetEmployeeInfo(ByVal EmpNo As Integer) As Employee

    End Interface

    <DataContract()> _

    Public Class Employee

      Private _Empno As Integer

      Private _Ename As String

      Private _Sal As Double

      Private _Deptno As Integer

    <DataMember()> _

      Public Property Empno() As Integer

       Get

        Return _Empno

       End Get

        Set(ByVal value As Integer)

         _Empno = value

        End Set

    End Property

    <DataMember()> _

      Public Property Ename() As String

       Get

        Return _Ename

       End Get

        Set(ByVal value As String)

         _Ename = value

        End Set

    End Property

    <DataMember()> _

      Public Property Sal() As Double

       Get

        Return _Sal

       End Get

        Set(ByVal value As Double)

         _Sal = value

        End Set

    End Property

    <DataMember()> _

      Public Property Deptno() As Integer

       Get

        Return _Deptno

       End Get

        Set(ByVal value As Integer)

         _Deptno = value

        End Set

    End Property

    End Class

    Modify "EmpService.vb" to match the following:

    Imports System.Data.SqlClient

    Imports System.Data

    Imports System.Configuration

    Public Class EmpService

      Implements IEmpService

    Public Function GetEmployeeInfo(ByVal EmpNo As Integer) As Employee Implements IEmpService.GetEmployeeInfo

    Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("cnNorthwind").ConnectionString)

    Using cmd As New SqlCommand("SELECT empno,ename,sal,deptno FROM dbo.emp WHERE empno=" & EmpNo, cn)

      cmd.Connection.Open()

       Using rdr As SqlDataReader = cmd.ExecuteReader

        If rdr.Read() Then

    Return New Employee With {.Empno = rdr(rdr.GetOrdinal("Empno")), .Ename = rdr(rdr.GetOrdinal("Ename")) & "", .Sal = rdr(rdr.GetOrdinal("sal")) & "", .Deptno = rdr(rdr.GetOrdinal("Deptno")) & ""}

       Else

         Return Nothing

       End If

    End Using

       cmd.Connection.Close()

      End Using

     End Using

    End Function

    Public Function GetNames() As System.Collections.Generic.List(Of String) Implements IEmpService.GetNames

      Dim EmployeeNames As New List(Of String)

    Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("cnNorthwind").ConnectionString)

       Using cmd As New SqlCommand("SELECT ename FROM dbo.emp", cn)

      cmd.Connection.Open()

       Using rdr As SqlDataReader = cmd.ExecuteReader

        If rdr.HasRows Then

         While rdr.Read

          EmployeeNames.Add(rdr(rdr.GetOrdinal("ename")))

         End While

          Return EmployeeNames

         Else

          Return Nothing

         End If

    End Using

       cmd.Connection.Close()

      End Using

     End Using

    End Function

    End Class

    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 4 hosted by Hostway
    Stay green...Green IT