WCF Service to display on a Winform its current data

Viewed 32

I'm making a 2-stage "reservation management" program that other Software interacts with via WCF messages. Clients can claim a reservation, and release a reservation they previously had laid claim to. I'd like all this reservation info to be viewable on a WinForm for the host.

What I'm not sure how to accomplish is getting data from the Service into my WinForm. Im still very green when it comes to WCF stuff, I followed the MSDN guide to get that skeleton, but they didnt go into much detail tying to GUIs, or having any stored info.

My Service:

namespace ReservationServiceLib
{
    public class reservation
    {
        public string location;
        public bool claimed;
        public string currentHolder;
        public reservation(string l)
        {
            location = l;
            claimed = false;
            currentHolder = "host";
        }
    }

    public class ReservationService : IReservationService
    {
        public bool reservationManagerLocked= false;
        public List<reservation> keys = new List<reservation>();
        private static Mutex managerLock = new Mutex();
            public bool GetAccess(string n1)
        {
            //get acceess lock for using the reservationManager
            return true;
        }
        public bool ClaimReservation(string rez, string clientN)
        {
            //Client requests/retrieves key
            if(reservationManagerLocked!=true)
            {
                int i = 999;
                i = keys.IndexOf(keys.Find(delegate (reservation x) { return x.location == rez; }));
                if((keys[i].claimed == false) && (i < 999))
                {
                    i = 999; 
                    keys[i].claimed = true; 
                    keys[i].currentHolder = clientN;
                    return true;
                }
             }
             return false;
        }
        public bool ReleaseReservation(string n1)
        {
            //Client relenquishes access to key
            return true;
        }

And my "host" Winform:

namespace ReservationManager
{
    public partial class ReservationManager : Form
    {
        public void populateComboBox()
        {
            for (int x = 0; x < dataGridView_IZone.Rows.Count-1; x++)
            {
                //comboBox_keyNames.Items.Add(dataGridView_IZone.Rows[x].Cells[0].Value);
            }
        }
       public IZoneManager()
        {
            
            //create Keys and add to service's store of keys
           

            //setup GUI
            InitializeComponent();

            // Step 1: Create a URI to serve as the base address.
            Uri baseAddress = new Uri("http://localhost:8000/ReservationServiceLib/");
            CalculatorService CSs = new CalculatorService();
            // Step 2: Create a ServiceHost instance.
            ServiceHost selfHost = new ServiceHost(typeof(ReservationService), baseAddress);
            try
            {
                // Step 3: Add a service endpoint.
                selfHost.AddServiceEndpoint(typeof(IReservation), new WSHttpBinding(), "ReservationService");

                // Step 4: Enable metadata exchange.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Step 5: Start the service.
                selfHost.Open();
                Console.WriteLine("The service is ready.");

            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
    }
}
0 Answers
Related