Step 1: Create a new WCF Service
Step 2: Add A Commom.Cs file in
App_Code folder.
And write these code.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- /// <summary>
- /// Summary description for Common
- /// </summary>
- public class Common
- {
- public static string str = ConfigurationManager.ConnectionStrings["conn"].ToString();
- SqlConnection conn = new SqlConnection(str);
- public Common()
- {
- }
- #region Check Login
- public bool Check_Login(string User_Name, string Password)
- {
- bool result = false;
- SqlCommand cmd = new SqlCommand("usp_check_login", conn);
- cmd.CommandTimeout = 0;
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@username", User_Name);
- cmd.Parameters.AddWithValue("@pass", Password);
- SqlDataReader dr;
- conn.Open();
- dr = cmd.ExecuteReader();
- dr.Read();
- if (dr[0].ToString() == "True")
- {
- result = true;
- }
- else
- {
- result = false;
- }
- conn.Close();
- return result;
- }
- #endregion
- # region Register
- public string Register_Login(string Username, string User_Pass, string F_Name, string L_Name, string Address1, string mobile, string City)
- {
- string result = "Error";
- SqlCommand cmd = new SqlCommand("Usp_Register_User", conn);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.CommandTimeout = 0;
- cmd.Parameters.AddWithValue("@Username1", Username);
- cmd.Parameters.AddWithValue("@User_Pass", User_Pass);
- cmd.Parameters.AddWithValue("@F_Name", F_Name);
- cmd.Parameters.AddWithValue("@L_Name", L_Name);
- cmd.Parameters.AddWithValue("@Address1", Address1);
- cmd.Parameters.AddWithValue("@mobile", mobile);
- cmd.Parameters.AddWithValue("@City", City);
- conn.Open();
- SqlDataReader dr;
- dr = cmd.ExecuteReader();
- dr.Read();
- if (dr[0].ToString().Contains("Error"))
- {
- result = "Error !!!";
- }
- else
- {
- result = "Succsess";
- }
- return result;
- }
- #endregion
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both code and config file together.
- [ServiceContract]
- public interface IService
- {
- [OperationContract]
- string GetData(int value);
- [OperationContract]
- bool Check_Login(String U_Id, String U_Pass);
- [OperationContract]
- [FaultContract(typeof(string))]
- string Register_Login(string Username, string User_Pass, string F_Name, string L_Name, string Address1, string mobile, string City);
- }
- // Use a data contract as illustrated in the sample below to add composite types to service operations.
- [DataContract()]
- public class ServiceData
- {
- [DataMember]
- public bool Result { get; set; }
- [DataMember]
- public string ErrorMessage { get; set; }
- [DataMember]
- public string ErrorDetails { get; set; }
- }

Join the conversation! Your thoughts help the community grow.