Create Table in Sql
Intially, database can be created with table as u like (i.e) say here i have create employee details. StoreProcedure to be create for Employee Details.
- Create database EmpDetails
- Create table "Employee"
- Create table Employee
- (EmployeeID numeric(18,0),FirstName varchar(25),LastName varchar(25),BirthDate datetime,City varchar(20), Country varchar(30))
- insert into Employee values (1126146,'Rajivi','Lathika','5/29/1995','Chennai','India');
- insert into Employee values(1126147,'Keerthi','Venkatesan','3/27/1993','Chennai','India');etc;,
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- -- =============================================
- -- Author: <Author,,Name>
- -- Create date: <Create Date,,>
- -- Description: <Description,,>
- -- =============================================
- Alter PROCEDURE GetEmpDetails
- -- Add the parameters for the stored procedure here
- @EmployeeID int=0
- AS
- BEGIN
- -- SET NOCOUNT ON added to prevent extra result sets from
- -- interfering with SELECT statements.
- SET NOCOUNT ON;
- SELECT FirstName, LastName, convert(char(10),BirthDate,101)BirthDate, City, Country
- FROM Employee WHERE EmployeeID=@EmployeeID
- -- Insert statements for procedure here
- --SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
- END
- GO
Now we successfully created the database.
Create Service
- Open Microsoft Visual Studio and follow these steps.
File->New->Project->WCF->WCF Service Application->(rename the form if u want) OK.
- Create a class file by add->class file.
Note: Here GetEmpDet,were you can create of ur own choice.Parameter "@EmployeeID"- namespace WcfService1
- {
- public class EmpNDet
- {
- public string GetEmpDet(string strSQLCon, string strEmpID)
- {
- string strXMLResult = string.Empty;
- DataSet DTEmpDet = new DataSet();
- try
- {
- var arrParameters = new SqlParameter[1];
- arrParameters[0] = new SqlParameter("@EmployeeID", SqlDbType.VarChar, 18);
- arrParameters[0].Value = strEmpID;
- DTEmpDet = SqlHelper.ExecuteDataset(strSQLCon, CommandType.StoredProcedure, "GetEmpDetails", arrParameters);
- DTEmpDet.Tables[0].TableName = "EmpDet";
- if (DTEmpDet != null)
- {
- strXMLResult = DTEmpDet.GetXml();
- }
- else
- {
- strXMLResult = "<EStatus>NORECORD</EStatus>";
- }
- }
- catch (Exception ex)
- {
- strXMLResult = "<EStatus>ERROR</EStatus><EMsg>" + ex.Message.ToString() + "</EMsg>";
- }
- return strXMLResult;
- }
- }
- }
we are going to pass to retrieve the employee details.
- In Solution Explorer,IService1.cs file which had been created to be clicked and start to code.
Purpose:
- namespace WcfService1
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
- [ServiceContract]
- public interface IService1
- {
- [OperationContract]
- string GetEmpDet(string strSQLCon, string strEmpID);
- // TODO: Add your service operations here
- }
- }
- Next step to code Service1.svc.
purpose:
Note: strResult to get the result from database in XML format.- namespace WcfService1
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
- // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
- public class Service1: IService1
- {
- string strResult = string.Empty;
- EmpNDet objEmpNDet = new EmpNDet();
- public string GetEmpDet(string strSQLCon, string strEmpID)
- {
- strResult = objEmpNDet.GetEmpDet(strSQLCon, strEmpID);
- return strResult;
- }
- }
- }


SubashPosted Sep 9, 2016, 12:44 AM
Nice
Keerthi VenkatesanPosted Mar 22, 2016, 3:27 AM
yes, your right. This is one way where WCF services allow to access .
Ammar ShaukatPosted Mar 21, 2016, 9:49 PM
what are you trying to do here i could't get you ?
Ammar ShaukatPosted Mar 21, 2016, 9:48 PM
good job. @keerthi why do not use Entity framework ? it is very easy .
Thiruppathi RPosted Mar 21, 2016, 1:27 AM
great job
Sonu ChaudharyPosted Mar 18, 2016, 2:58 PM
good one