Ejemplo n.º 1
0
        private void Connect()
        {
            if (proxy == null)
            {
                try
                {
                    this.localClient          = new ChatUser();
                    this.localClient.UserName = loginTxtBoxUName.Text.ToString();
                    InstanceContext context = new InstanceContext(this);
                    proxy = new Duplex_ChatServiceClient(context);

                    proxy.Open();

                    proxy.InnerDuplexChannel.Faulted += new EventHandler(InnerDuplexChannel_Faulted);
                    proxy.InnerDuplexChannel.Opened  += new EventHandler(InnerDuplexChannel_Opened);
                    proxy.InnerDuplexChannel.Closed  += new EventHandler(InnerDuplexChannel_Closed);
                    proxy.ConnectAsync(this.localClient);
                    proxy.ConnectCompleted += new EventHandler <ConnectCompletedEventArgs>(proxy_ConnectCopleted);
                }
                catch (Exception exception)
                {
                    loginTxtBoxUName.Text        = exception.Message.ToString();
                    loginLabelStatus.Content     = "Offline";
                    loginButtonConnect.IsEnabled = true;
                }
            }
            else
            {
                HandleProxy();
            }
        }
Ejemplo n.º 2
0
        void chatListBoxNames_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBoxItem item = chatListBoxNames.SelectedItem as ListBoxItem;

            if (item != null)
            {
                this.receiver = this.OnlineClients[item];
            }
        }