繁体   English   中英

WCF 在 Winform 上显示其当前数据的服务

[英]WCF Service to display on a Winform its current data

我正在制作一个两阶段的“预订管理”程序,其他软件通过 WCF 消息与之交互。 客户可以要求保留,并释放他们之前提出要求的保留。 我希望所有这些预订信息都可以在主机的 WinForm 上查看。

我不确定如何将数据从服务中获取到我的 WinForm 中。 当谈到 WCF 的东西时,我仍然非常绿色,我按照 MSDN 指南获取了那个骨架,但他们没有 go 与 GUI 相关的更多细节,或者有任何存储的信息。

我的服务:

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;
        }

还有我的“主持人”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();
            }
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM