Sunday, 2 February 2014

hiii guys here i am for posting my work i am working as software developer at lobaan software

<h2>In this company my first task is Create WCF Rest Service And call this service method  using jquery Ajax</h2>
So I m Posting this demo here its successfully work
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    {
        DataClasses1DataContext db = new DataClasses1DataContext();
        public Employee AddEmployee(string  id)
        {
            var data = db.Emps.Where(e => e.EID ==Convert.ToInt32( id)).Select(e => e);

            return new Employee { EmpAddress = data.SingleOrDefault().EApproval, EmpName = data.SingleOrDefault().EName };
        }
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<h1>Here Interface of my service</h1>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebGet(ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,UriTemplate="GetData/{id}",BodyStyle=WebMessageBodyStyle.Wrapped)]
        Employee AddEmployee(string  id);


        // 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 Employee
    {
        [DataMember]
        public string EmpName { get; set; }
        [DataMember]
        public string EmpAddress { get; set; }
    }
}

No comments:

Post a Comment