Wcf Service Basic Part Eight

At last session we got the idea about the interface and some attributes which are required when we want to create wcf service . Now let discuss the implementation of the interface . This is implementation of the interface . if you ever worked with ADO.NET then this should be familiar with you . This is the implementation of the interface when we pass the paraments inside the method .


  [OperationContract]
     string AddNewEmployee(string id, string name, string address, string city, string salary);


   public string AddNewEmployee(string id, string name, string address, string city, string salary)
        {
            try
            {
                SqlConnection con = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("prcAddEmp", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("v_eid", id);
                cmd.Parameters.AddWithValue("v_ename", name);
                cmd.Parameters.AddWithValue("v_eadd", address);
                cmd.Parameters.AddWithValue("v_ecity", city);
                cmd.Parameters.AddWithValue("v_esal", salary);
                con.Open();
                int rows = cmd.ExecuteNonQuery();
                return rows;
            }
            catch (Exception e1)
            {
                throw e1;
            }

        }

when we pass the class inside the method then implementation should be look like this .


  [OperationContract]
  string Balance(AccountBalance accountBalance);



 public string Balance(AccountBalance accountBalance)
        {
            string Message;

            int j = Convert.ToInt32(accountBalance.Account_Number);
            //Create SqlConnection
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                con.Open();
                SqlCommand sda = new SqlCommand("SELECT  * FROM Account_Details WHERE  Account_Number='" + accountBalance.Account_Number + "'", con);
                sda.Parameters.AddWithValue("@Account_Number", accountBalance.Account_Number);
                sda.CommandType = CommandType.Text;
                sda.ExecuteNonQuery();

            }


            Message = "Record is inserted successfully";
            return Message;


        }




No comments:

Post a Comment