WCF Tutorial, Part 4: Service Implementation

01. December 2013 WCF 0
  • Create a WCF Service Library and name it RoomReservationService.
  • Add references to
    • RoomReservationContracts
    • RoomReservationData
  • Remove the Data Contract class and modify the RoomReservationService.cs as bellow:
using System;
using System.ServiceModel;
using RoomReservationContracts;
using RoomReservationData;
 
namespace RoomReservationservice
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class RoomReservationService : IRoomService
    {
        public bool ReserveRoom(RoomReservation roomReservation)
        {
            var data = new RoomReservationData.RoomReservationData();
            data.ReserveRoom(roomReservation);
            return true;
        }
 
        public RoomReservation[] GetRoomReservations(DateTime fromTime, DateTime toTime)
        {
            var data = new RoomReservationData.RoomReservationData();
            return data.GetReservations(fromTime, toTime);
        }
    }
}

The service class RoomReservationService implements the interface IRoomService. The service is implemented just by invoking the appropriate methods of the RoomReservationData class.

Following figure shows the assemblies we have created yet and their dependencies.


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.