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.





No comments:

Post a Comment