private void btnCheckValue_Click(object sender, RoutedEventArgs e) { try { msg.AppendLine("Calling service @" + DateTime.Now); msg.AppendLine("call IncrementNumber " + client.IncrementNumber().ToString()); msg.AppendLine("SessionID " + client.InnerChannel.SessionId); //lblMessage.Content = "Calling service @" + DateTime.Now; //lblMessage.Content += "\n1st call value " + client.IncrementNumber().ToString(); //lblMessage.Content += "\n2nd call value " + client.IncrementNumber().ToString(); //lblMessage.Content += "\n3rd call value " + client.IncrementNumber().ToString(); //lblMessage.Content += "\n4th call value " + client.IncrementNumber().ToString(); //lblMessage.Content += "\n\n\nSessionID " + client.InnerChannel.SessionId; //lblMessage.Content = msg.ToString(); listBox.Items.Add(msg.ToString()); } catch (CommunicationException) { if (client.InnerChannel.State == CommunicationState.Faulted) { msg.AppendLine("\nSession timed out. Your existing session will be lost. A new session will be created!"); client = new SimpleServiceClient(); } } }
private void buttonServiceBehavior_Click(object sender, EventArgs e) { InstanceContext instanceContext = new InstanceContext(this); SimpleServiceClient client = new SimpleServiceClient(instanceContext); //SimpleServiceClient client = new SimpleServiceClient(); MessageBox.Show($"Number after first call = {client.IncrementNumber()}"); MessageBox.Show($"Number after second call = {client.IncrementNumber()}"); MessageBox.Show($"Number after third call = {client.IncrementNumber()}"); //// Handling session timeout exception //try //{ // MessageBox.Show($"Number = {client.IncrementNumber()}"); //} //catch(CommunicationException) //{ // if (client.State == CommunicationState.Faulted) // { // MessageBox.Show($"Session timed out and existing session is lost. A new session will now be created."); // client = new SimpleServiceClient(); // } //} }