Create WPF Client to use the Web-Service

These are the steps for adding a WPF client application to the Authenticator Solution we are working on:

1. Create the additional project

In the Solution Explorer window, first select the Authenticator solution and then select Add | New Project and choose the WPF Application template.

Add_Project_WPFApp

Name it IdentityClient and click OK

2. Add a reference to the WebService we published

In the Solution Explorer window, first select the IdentityClient project and then select Add | New Service Reference

Choose enter the parameters that were entered when we published the WebService and click Discover

A window like this should appear:

Add_Service_Reference_01

You can see 3 methods we created earlier:

  • HelloWorld
  • AddUser
  • GetUserIdentifier

Click OK

3. Design the MainWindow

In the MainWindow.xaml, add a Button, a TextBox and a ListBox, with these lines:

<Grid>
<Button x:Name=”button” Content=”Test” HorizontalAlignment=”Left” Margin=”44,27,0,0″ VerticalAlignment=”Top” Width=”75“/>
<TextBox x:Name=”textBox” Height=”23″ Margin=”44,66,10,0″ TextWrapping=”Wrap” Text=”” VerticalAlignment=”Top”/>
<ListBox x:Name=”listBox” Margin=”44,102,10,10″/>
</Grid>

The window should then look like this:

IdentityClient

4. Write the code

In the MainWindow.xaml, double click the Button to add the event-handler. This code will be added to the MainWindow.xaml.cs code:

private void button_Click(object sender, RoutedEventArgs e)

Adapt the MainWindow.xaml.cs code to be this:

using System;
using System.Windows;
using IdentityClient.ServiceReference1;

namespace IdentityClient
{

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>

public partial class MainWindow : Window
{

public MainWindow()
{

InitializeComponent();

}

private async void button_Click(object sender, RoutedEventArgs e)
{

Guid aGuid;
int OTP; //for checking a OneTime Password
string TheMessage;
string aUser = “fred.flintstone@gmail.com”;
string aPwd = “Th1s1sMyP@ssw0rd”;
listBox.Items.Add(“Clicked”);
IdentityBrokerClient client = new IdentityBrokerClient();
listBox.Items.Add(“IdentityBrokerClient client = new IdentityBrokerClient();”);

// Test to add Fred
TheMessage = client.AddUserAsync(aUser, aPwd);
listBox.Items.Add(“client.AddUserAsync”);
listBox.Items.Add(TheMessage);
listBox.Items.Add(“——————“);

// Test to Get Fred his Guid
aGuid = await client.GetUserIdentifierAsync(aUser, aPwd);
listBox.Items.Add(“client.GetUserIdentifier”);
listBox.Items.Add(aGuid.ToString());
client.Close();

}

}

}

The test application creates a similar output like this:

IdentityClient_Run01

Post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.