Thursday, April 16, 2015

How to Create a WCF Service library

  • Add the WCF Service library
  • Add the service host project to the solution

  • Add the  Business Objects class library to the solution
  • Add the Business Logic class library to the solution 
  • Add the Data Access layer class library to the solution 
  • Add the DTObjects class library to the solution
  • Add the DTOStudent  Class to the DTObjects project

    • Add the System.Runtime.Serialization as reference to the project 
    • Decorate the Data Contract as DTOStudent Class and add few properties and decorate it as data member



  •   Add the Student to the business object and add the class properties


  • Add BOAssembler class to the business logic and add StudentBusinesObjects Project  and DTOobjects project as references
  • Implement the AssembleStudentBO method to the BOAssembler class


  • Add DTOAssembler  class and Implement the AssembleStudentDTO method


  • Implement the Data Access layer
  • Add the connection string as the key of the web.configration file using the settings file modifications




  • Change the key name to student
  • if you open the web.config file you can see the changes what are made by adding the connection string key
  •  Add the  IDALDBConnection interface to the project and add the signatures
  • Add the DbConnection Class to the DAL and add the DbConnection and DbTransaction abstract class members to the DBConnection Class 

  •  Implement  the connection string method


  • implement the ExecuteNonQuery method

  • implement the Execute DataSet method



  • implement the business object Student class methods and add the constructor
    implement the add Student method 

  • implement the Get Student method 


  • Add the IStudentService Interface to Business Logic layer and add the two methods
  • implement the method in the StudentService class

  • Implement the IStudentManagementService interface to StudentServiceLibrary
  • Decorate the service as ServiceContract  and methods as OperationContract

  • Implementation of the StudentManagementService class


  • Implementation of the StudentServiceHost layer
  • Rename the SVC class to the StudenService and delete the cs class of the SVC file
  • Remove the CodeBehind tag and set the Service="StudentServiceLibrary.StudentManagementService"
  • Open the StudentServiceLibrary app.config file using the WCF editor and change the service name to StudentServiceLibrary.StudentManagementService.


  • Now Change the end point  basicHttpBinding contract property to the
    " StudentServiceLibrary.IStudentManagementService "


     
  • Now open the App.config file and copy the <services> tag element  and paste in to the Web.config file 


  • Now u can successfully  run the service


  • Add the student to the database and Get the all student add by the service 



Saturday, March 28, 2015

Implement WCF service with Linq to SQL dbml class.

Implement WCF service with in few steps



Add the new WCF Service application 
















Add the business Logic class library to the project


Add  the data access layer dbml class to the project

 

Connect to the database server  from the server explore




Drag and drop the tables to left hand side of the screen and drag and drop the stored procedures and functions to right hand side of the screen





Once you trying  to add the tables and stored procedures , you fill get this message
then click "No" button to, save the  connection string without the sensitive data


Once you add the classes and projects to the solution, hierarchy should be look like this




Add the Student Class to the business Logic project and add the properties same as student table
in the database.


 
Create the student class constructor and assign the new datastudent object










Implement the add student method to the student class

NOTE :
if you add the out put parameter to the stored procedure,you have to pass the student Id as reference parameter,therefore create the null able int variable called id and assign it to the student id and pass the id to the stored procedure.

 Implement the GetStudent method to the student class

 

Add the business logic as reference to the service layer

Add the  IStudentManagement interface to the service layer and decorate is as service contract,add few  method  signatures  as operation contract

 

 Add the  StudentManagement class to the service layer and inherit IStudentManagement
Implement the methods.
















Remove the StudentManagementService.svc code behind cs class
and modify the service class name

<%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceStudent.StudentManagement" %>

If u successfully Implement the service it time to run the service.