Create a WCF service using the Entity Framework and consume after hosting it in IIS
----------------------------------------------------------------------------------------------------------------
Step1:Create table
USE [Chinna]
GO
/****** Object: Table [dbo].[Student] Script Date: 21-10-2014 12:06:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Student](
[id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[age] [int] NULL,
CONSTRAINT [stu_pk] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
step2:create procedures for inser,update,delete
Insert
USE [Chinna]
GO
/****** Object: StoredProcedure [dbo].[Insert_student] Script Date: 21-10-2014 12:08:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Insert_student]
(
@Name nvarchar(50),
@age int
)
as
begin
insert into Student(Name,age) values(@Name,@age);
end
GO
Update
USE [Chinna]
GO
/****** Object: StoredProcedure [dbo].[Update_student] Script Date: 21-10-2014 12:09:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Update_student]
(
@id int,
@Name nvarchar(50),
@age int
)
as
begin
update Student set Name=@Name,age=@age where id=@id;
end
GO
Delete
USE [Chinna]
GO
/****** Object: StoredProcedure [dbo].[Delete_student] Script Date: 21-10-2014 12:09:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Delete_student]
(
@id int
)
as
begin
delete from Student where id=@id;
end
GO
Step3:go to vs run as administrator -->file-->new-->class lib-->Studentclaslibr-->ok
Remove -class1.cs file
add-->addnewitem--->wcf service-->ok
---goto solution explorer --->addnew item-->select ado.net entity frmae work-->StudentModel.edmx--->ok
---->select --generate from database
select the tables and sp's
mapping the stored procedured
rc-->student entity
host the wcf service using iis
add-->add new item-->wcf service-->wcf servicehost in the same path-->ok
add the studentclasslibr.dll to the host
----------------------------------------------------------------------------------------------------------------
Step1:Create table
USE [Chinna]
GO
/****** Object: Table [dbo].[Student] Script Date: 21-10-2014 12:06:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Student](
[id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[age] [int] NULL,
CONSTRAINT [stu_pk] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
step2:create procedures for inser,update,delete
Insert
USE [Chinna]
GO
/****** Object: StoredProcedure [dbo].[Insert_student] Script Date: 21-10-2014 12:08:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Insert_student]
(
@Name nvarchar(50),
@age int
)
as
begin
insert into Student(Name,age) values(@Name,@age);
end
GO
Update
USE [Chinna]
GO
/****** Object: StoredProcedure [dbo].[Update_student] Script Date: 21-10-2014 12:09:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Update_student]
(
@id int,
@Name nvarchar(50),
@age int
)
as
begin
update Student set Name=@Name,age=@age where id=@id;
end
GO
Delete
USE [Chinna]
GO
/****** Object: StoredProcedure [dbo].[Delete_student] Script Date: 21-10-2014 12:09:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Delete_student]
(
@id int
)
as
begin
delete from Student where id=@id;
end
GO
Step3:go to vs run as administrator -->file-->new-->class lib-->Studentclaslibr-->ok
Remove -class1.cs file
add-->addnewitem--->wcf service-->ok
---goto solution explorer --->addnew item-->select ado.net entity frmae work-->StudentModel.edmx--->ok
---->select --generate from database
click Next
click Next
select the tables and sp's
click finish
rc-->student entity
create the interface for service
implement the iservice in service class
host the wcf service using iis
add-->add new item-->wcf service-->wcf servicehost in the same path-->ok
add the studentclasslibr.dll to the host
and create the iis path to the wcfservice host and
service is created now
No comments:
Post a Comment