using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using System.ServiceModel.Web; using System.ServiceModel.Activation; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Runtime.Serialization.Json; using System.Web.Script.Services; using System.ServiceModel.Channels; using System.Web.Services; using nmsSetup; // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service2" in code, svc and config file together. [ServiceContract] public class Service2 { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString); //------------------------------Bind State-----------------// [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] public string viewState() { System.Web.Script.Serialization.JavaScriptSerializer RAJ = new System.Web.Script.Serialization.JavaScriptSerializer(); //string strConnection = "Data Source=SONY-PC; Initial Catalog = DB_Reveals;Integrated Security=True"; List lst = new List(); //using (SqlConnection con = new SqlConnection(strConnection)) //{ con.Open(); SqlCommand cmd = new SqlCommand("viewState", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader dr = cmd.ExecuteReader(); PRPSetup obj; if (dr.HasRows) { while (dr.Read()) { obj = new PRPSetup(); obj.id = dr["id"].ToString(); obj.name = dr["name"].ToString(); lst.Add(obj); } } dr.Dispose(); cmd.Dispose(); con.Close(); //} return RAJ.Serialize(lst); } //------------------------------Bind District-----------------// [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] public string viewDistrict(string ID) { System.Web.Script.Serialization.JavaScriptSerializer RAJ = new System.Web.Script.Serialization.JavaScriptSerializer(); //string strConnection = "Data Source=SONY-PC; Initial Catalog = DB_Reveals;Integrated Security=True"; List lst = new List(); //using (SqlConnection con = new SqlConnection(strConnection)) //{ con.Open(); SqlCommand cmd = new SqlCommand("viewDistrict", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", ID); SqlDataReader dr = cmd.ExecuteReader(); PRPSetup obj; if (dr.HasRows) { while (dr.Read()) { obj = new PRPSetup(); obj.id = dr["id"].ToString(); obj.name = dr["name"].ToString(); lst.Add(obj); } } dr.Dispose(); cmd.Dispose(); con.Close(); //} return RAJ.Serialize(lst); } }