Employee information SOA service

The following is a sample code for employee service to give an idea as a reference implementation for a REST-based web service:

    /// <summary> 
/// This class exposes the APIs related to Employee in HR Database
/// </summary>
[Route("api/[controller]")]
public class EmployeeController : Controller
{
private SOAContext soaContext;
private IEmployeeManager _manager;


public EmployeeController(IEmployeeManager employeeManager)
{
_manager = employeeManager;
}

/// <summary>
/// Gets the list of all Employees
/// Usage: GET api/employee
/// </summary>
/// <returns></returns>
[HttpGet]
public IEnumerable<Employee> Get()
{
soaContext = new SOAContext();
soaContext.Initialize();

var retVal = _manager.GetListofAllEmployees();
soaContext.Close();
return retVal;
}

If your environment is configured to use localhost:5000 for testing, then the URL to test this REST-based SOA service shall be http://localhost:5000/api/employee, which will then give you the list of all employees.

We can configure our solution setup to return the data in the JSON or XML format or both of them based on the client's request.

From the preceding code, we see how this employee SOA information service uses the context and closes it, which is provided by the SOA services library.

We do not need to go into the details of implementation for the underlying business layers, data access layers, and other stuff in general for understanding the SOA services design. But since it's the first web service code that we're looking at, we will take a look at all the steps of the code up to the database level.

You can also see the full source code provided in the form of projects for each chapter, which is shared with you along with the book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.165.115