BrainDump
  Home arrow BrainDump arrow Page 4 - Developing an Object Oriented Business Com...
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? 
BRAINDUMP

Developing an Object Oriented Business Component Using WCF and Visual Studio 2008
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2007-10-31

    Table of Contents:
  • Developing an Object Oriented Business Component Using WCF and Visual Studio 2008
  • Understanding the WCF Business Component
  • Understanding the WCF Business Component: Source Code for Entity classes
  • Understanding the WCF Business Component: Source Code for Business Logic
  • Understanding the WCF Business Component: Source Code for “DBHelper”

  • 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 an Object Oriented Business Component Using WCF and Visual Studio 2008 - Understanding the WCF Business Component: Source Code for Business Logic


    (Page 4 of 5 )

    To enable applications to utilize the services of WCF Service, an interface must be defined. The client accesses business objects and executes the methods which are defined in this interface.

    “IProductService” is an interface defined exclusively for the above purpose. It contains all the methods which are accessible to the client. It is defined as follows:


    <ServiceContract()> _

      Public Interface IProductService


    <OperationContract()> _

      Function GetProductInfo(ByVal ProductID As Integer) As Product


    <OperationContract()> _

      Function GetProductsLookup() As DataTable


    <OperationContract()> _

      Function GetProductsList() As Products


    <OperationContract()> _

      Sub Add(ByVal p_Product As Product)


    <OperationContract()> _

      Sub Update(ByVal p_Product As Product)


    <OperationContract()> _

      Sub Delete(ByVal p_Product As Product)


    <OperationContract(name:="DeleteProductByID")> _

      Sub Delete(ByVal p_ProductID As Integer)


    End Interface

    The above is simply an interface, which always contain abstract methods (or methods without any code). It has to be implemented using another class to make it a concrete class. “ProductFactoryService” is the class which implements the structure defined in the “IProductService” interface and it is defined as follows:


    Imports System.Data

    Imports System.Data.SqlClient


    Public Class ProductFactoryService

      Implements IProductService


    Public Function GetProductInfo(ByVal ProductID As Integer) As Product  Implements IProductService.GetProductInfo

    Dim dr As DataRow = DBHelper.getRow("SELECT ProductID, ProductName, UnitPrice, UnitsInStock, UnitsOnOrder FROM dbo.Products WHERE ProductID=" & ProductID)

      If dr Is Nothing Then

        Return Nothing

      Else

    Return New Product With {.ProductID = dr("ProductID"), .ProductName = dr("ProductName") & "", .UnitPrice = dr("UnitPrice") & "", .UnitsInStock = dr("UnitsInStock") & "", .UnitsOnOrder = dr("UnitsOnOrder") & ""}

      End If

    End Function


    Public Function GetProductsLookup() As System.Data.DataTable Implements IProductService.GetProductsLookup

    Return DBHelper.getDataTable("SELECT ProductID, ProductID + ' - ' + ProductName AS ProductName FROM dbo.Products")

    End Function


    Public Function GetProductsList() As Products Implements IProductService.GetProductsList

      Dim clnProducts As New Products

    For Each dr As DataRow In DBHelper.getDataTable("SELECT ProductID, ProductName, UnitPrice, UnitsInStock, UnitsOnOrder FROM dbo.Products").Rows

    clnProducts.Add(New Product With {.ProductID = dr("ProductID"), .ProductName = dr("ProductName") & "", .UnitPrice = dr("UnitPrice") & "", .UnitsInStock = dr("UnitsInStock") & "", .UnitsOnOrder = dr("UnitsOnOrder") & ""})

      Next

       Return clnProducts

      End Function


    Public Sub Add(ByVal p_Product As Product) Implements IProductService.Add

    DBHelper.SQLExecute("INSERT INTO dbo.Products(ProductName, UnitPrice, UnitsInStock, UnitsOnOrder) VALUES ('" & p_Product.ProductName & "'," & p_Product.UnitPrice & "," & p_Product.UnitsInStock & "," & p_Product.UnitsOnOrder & ")")

    End Sub


    Public Sub Delete(ByVal p_Product As Product) Implements IProductService.Delete

      Me.Delete(p_Product.ProductID)

    End Sub


    Public Sub Update(ByVal p_Product As Product) Implements IProductService.Update

    DBHelper.SQLExecute("UPDATE dbo.Products SET ProductName='" & p_Product.ProductName & "', UnitPrice=" & p_Product.UnitPrice & ", UnitsInStock=" & p_Product.UnitsInStock & ", UnitsOnOrder=" & p_Product.UnitsOnOrder & " WHERE ProductID=" & p_Product.ProductID)

    End Sub


    Public Sub Delete(ByVal p_ProductID As Integer) Implements IProductService.Delete

    DBHelper.SQLExecute("DELETE FROM dbo.Products WHERE ProductID = " & p_ProductID)

    End Sub


    End Class

    You can observe that, each operation (or method) in the above class works with a utility class named “DBHelper,” which is a common gateway for data access.

    More BrainDump Articles
    More By Jagadish Chaterjee


       · Hai,This is my next contribution following a series on WCF programming using...
     

    BRAINDUMP ARTICLES

    - Internet Explorer 8 Review
    - Nilpo`s Top Windows Add-Ons
    - Beginning Silverlight 2.0 Development using ...
    - Fixing Vista`s Troubles
    - Preparing Windows Images for Mass Deployment
    - The Trouble With Vista
    - Slipstreamed and Unattended Windows Installa...
    - Microsoft Office SharePoint Server
    - Microsoft Office SharePoint Designer
    - Microsoft Windows SharePoint Services 3.0
    - Microsoft Live Mesh Overview
    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics





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