As per your given code suppose I have webmethods for Delete and Update too,
And I need to consume them(WebMethods) in my web application where I also have to handle Transaction,
Can you provide with example of codes while consuming method, transaction should also gets handle.
Since I cannot use connection.BeginTransaction in my Consuming application becoz connection part is run inside webmethod
e.g.
/Application Consuming Webmethod
try
{
service1.InsertRow(param1, param2);
service1.DeleteRow(param3, param4);
service1.UpdateRow(param5, param6);
}
Catch
{
}
web Service code...........
[OperationContract]
public string InsertRow(string empname,string designation)
{
SqlConnection dbConn = null;
dbConn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["insightconnection"].ToString());
SqlCommand cmd;
SqlDataReader dr;
dbcon.Open();
spcmd = new SqlCommand("SP_InsertRow", spcon);
spcmd.CommandType = CommandType.StoredProcedure;
spcmd.Parameters.Add(new SqlParameter("@EMPName", empname));
spcmd.Parameters.Add(new SqlParameter("@DEsignation", designation));
dr = cmd.ExecuteReader();
return "inserted......!!! ";
}
Stored Procedure code..............
create PROCEDURE [dbo].[SP_InsertRow]
@EMPName varchar(max),
@DEsignation varchar(max)
AS
BEGIN
SET NOCOUNT ON;
insert into EMPDetails values(@EMPName,@DEsignation)
End