Implementing the TestService WCF Service
The WCF Service class called TestService implements the WCF Service Contract implemented earlier -- it defines the two methods declared in the WCF Service Contract. Here's what the class looks like:
<%@ ServiceHost Language="C#" Debug="true" Service="RESTService.TestService" CodeBehind="TestService.svc.cs" %>
using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
namespace RESTService
{
[ServiceContract]
public interface ITestService
{
[OperationContract]
[WebGet]
Employee GetEmployee(Int32 employeeID);
[WebInvoke]
Employee PostEmployee(Int32 employeeID);
}
[DataContract(Namespace = "")]
public class Employee
{
[DataMember]
public Int32 EmployeeID { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
[DataMember]
public String Address { get; set; }
}
public class TestService : ITestService
{
public Employee GetEmployee(Int32 employeeID)
{
return new Employee { EmployeeID = employeeID, FirstName = "Joydip", LastName = "Kanjilal" };
}
public Employee PostEmployee(Int32 employeeID)
{
return new Employee { EmployeeID = employeeID, FirstName = "Joydip", LastName = "Kanjilal" };
}
}
}
No comments:
Post a Comment