using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace Employee { // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config. [ServiceContract] public interface IService1 { [OperationContract] List<CompositeType> GetEmployee(String Employeerid); [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: Add your service operations here } // Use a data contract as illustrated in the sample below to add composite types to service operations [DataContract] public class CompositeType { int empid; string ename; string address; string city ; string state ; string employeerid; [DataMember] public int Empid { get { return empid; } set { empid = value; } } [DataMember] public string Ename { get { return ename; } set { ename = value; } } [DataMember] public string Address { get { return address; } set { address = value; } } [DataMember] public string City { get { return city; } set { city = value; } } [DataMember] public string State { get { return state; } set { state = value; } } [DataMember] public string Employeerid { get { return employeerid; } set { employeerid = value; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace Employee { // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config. public class Service1 : IService1 { public string[] GetEmployeerid() { String strConnection = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString; SqlConnection conn = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand("select * from Employeertable ", conn); conn.Open(); } public CompositeType GetDataUsingDataContract(CompositeType composite) { List<compositetype> Employee = new List<compositetype>(); { String strConnection = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString; SqlConnection conn = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand("select * from Employeetable ", conn); conn.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Employee obj = new Employee(); obj.Empid = Convert.ToInt32(dt.Rows[i]["Empid"].ToString()); obj.Ename = dt.Rows[i]["Ename"].ToString(); obj.Address = dt.Rows[i]["Address"].ToString(); obj.City = dt.Rows[i]["City"].ToString(); obj.State = dt.Rows[i]["State"].ToString(); obj.Employeerid = dt.Rows[i]["Employeerid"].ToString(); Employee.Add(obj); } } conn.Close(); } return Employee; } } }
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)