private void ConnectToServer() { ClientCallback callback = new ClientCallback(); try { GameServiceClient client = new GameServiceClient( new InstanceContext(callback)); username = tbfName.Text.Trim(); client.ClientConnected(username); ChatWindow mainWindow = new ChatWindow(); mainWindow.Client = client; mainWindow.Callback = callback; mainWindow.Username = username; mainWindow.Title = username; this.Close(); mainWindow.Show(); } // catch (FaultException<UserExistsFault> ex) catch (FaultException ex) { MessageBox.Show("this user already connected!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); // MessageBox.Show(ex.Detail.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Login(string userName, string password) { GameCallback callback = new GameCallback(); try { GameServiceClient client = new GameServiceClient(new InstanceContext(callback)); client.ClientConnected(userName, password); GameOptionsWindow optionWindow = new GameOptionsWindow(); optionWindow.Client = client; optionWindow.CallBack = callback; optionWindow.Username = userName; optionWindow.Title = userName; this.Close(); optionWindow.Show(); } catch (FaultException <UserExistsFault> ex) { MessageBox.Show(ex.Detail.Message, "Oops!", MessageBoxButton.OK, MessageBoxImage.Information); } catch (FaultException ex) { MessageBox.Show(ex.Message, "Error occurred!", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error occurred!", MessageBoxButton.OK, MessageBoxImage.Error); } }