Ejemplo n.º 1
0
        /*
        private MessengerClient CreateClient()
        {
            string key0 = ConfigurationManager.AppSettings["Key0"];
            System.ServiceModel.BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            EndpointAddress ep = new EndpointAddress("http://localhost:55560/MessengerService.svc");
            //EndpointAddress ep = new EndpointAddress("http://li4shi2.azurewebsites.net/MessengerService.svc");
            return new MessengerClient(binding, ep);
        }
         */
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                //mClient = CreateClient();
                //mClient = new MessengerClient();
                //mClient = new MessengerClient(new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None), new EndpointAddress("http://192.168.98.129:8000/Messenger"));
                mClient = new MessengerClient(new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None), new EndpointAddress("http://localhost:8000/Messenger"));

                // get ip address
                string ipaddr = string.Empty;
                IPHostEntry host;
                host = Dns.GetHostEntry(Dns.GetHostName());
                foreach (IPAddress ip in host.AddressList)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        ipaddr = ip.ToString();
                        break;
                    }
                }

                //mUserId = DateTime.Now.ToString("hhmmss");
                mUserId = System.Environment.MachineName + "-" + System.Diagnostics.Process.GetCurrentProcess().Id;
                if (mClient.Login(mUserId) == false)
                {
                    MessageBox.Show("Login failed.");
                    Application.ExitThread();
                    return;
                }
                this.Text = mUserId;
                string list = mClient.GetMemberList();
                updateMemberList(list);
                receiveMemberCompletedHandler = new EventHandler<ReceiveMemberListCompletedEventArgs>(OnReceiveMemberListCompleted);
                mClient.ReceiveMemberListCompleted += receiveMemberCompletedHandler;
                mClient.ReceiveMemberListAsync(mUserId);
                receiveConnectionCompletedHandler = new EventHandler<ReceiveConnectionCompletedEventArgs>(OnReceiveConnectionCompleted);
                mClient.ReceiveConnectionCompleted += receiveConnectionCompletedHandler;
                mClient.ReceiveConnectionAsync(mUserId);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Application.ExitThread();
            }
        }