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.


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:


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:

<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″/>

The window should then look like this:


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()



private async void button_Click(object sender, RoutedEventArgs e)

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

// Test to add Fred
TheMessage = client.AddUserAsync(aUser, aPwd);

// Test to Get Fred his Guid
aGuid = await client.GetUserIdentifierAsync(aUser, aPwd);




The test application creates a similar output like this:



Post a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s