Download presentation
Presentation is loading. Please wait.
Published byEllen Stafford Modified over 9 years ago
3
3
4
4
5
5
6
6 [ServiceContract] public interface IJokeOfTheDayService { [OperationContract] string GetJoke(int jokeStrength); }
7
7
8
8 public class JokeOfTheDayService : IJokeOfTheDayService { public string GetJoke(int jokeStrength) { string result = "Invalid strength"; switch (jokeStrength) { case 0: result = "Joke 0 text"; break; case 1: result = "Joke 1 text"; break; case 2: result = "Joke 2 text"; break; } return result; } }
9
9
10
10
11
11
12
12
13
13
14
14 JokeOfTheDayService.JokeOfTheDayServiceClient jokeService; // Constructor public MainPage() { InitializeComponent(); jokeService = new JokeOfTheDayService.JokeOfTheDayServiceClient(); jokeService.GetJokeCompleted += new EventHandler<JokeOfTheDayService. GetJokeCompletedEventArgs> (jokeService_GetJokeCompleted); }
15
15 JokeOfTheDayService.JokeOfTheDayServiceClient jokeService; // Constructor public MainPage() { InitializeComponent(); jokeService = new JokeOfTheDayService.JokeOfTheDayServiceClient(); jokeService.GetJokeCompleted += new EventHandler<JokeOfTheDayService. GetJokeCompletedEventArgs> (jokeService_GetJokeCompleted); }
16
16 JokeOfTheDayService.JokeOfTheDayServiceClient jokeService; // Constructor public MainPage() { InitializeComponent(); jokeService = new JokeOfTheDayService.JokeOfTheDayServiceClient(); jokeService.GetJokeCompleted += new EventHandler<JokeOfTheDayService. GetJokeCompletedEventArgs> (jokeService_GetJokeCompleted); }
17
17
18
18 void jokeService_GetJokeCompleted(object sender, JokeOfTheDayService.GetJokeCompletedEventArgs e) { if (!e.Cancelled) { jokeTextBlock.Text = e.Result; } }
19
19 private void getJokeButton_Click(object sender, RoutedEventArgs e) { int strength = 0; if (int.TryParse(strengthTextBox.Text, out strength)) { jokeService.GetJokeAsync(strength); } }
20
20
21
21
22
22
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.