Click here to Skip to main content
12,063,909 members (61,809 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: WCF
Iservice1.cs:

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; }
        }
    }
}


Service1.cs:


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;
        }
 
        }
    }

[edit]Code block added - OriginalGriff[/edit]
Posted 31-Dec-12 21:51pm
Edited 31-Dec-12 22:08pm
v2
Comments
prashant patil 4987 1-Jan-13 4:12am
   
question not clear...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160204.4 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100