Create a Test Windows Forms Application
-
Return to the Visual Studio solution, right-click the
solution, and select Add | New Project.
-
Select Windows Forms Application from the Windows
templates, provide a name (such as SalesTestApp), and click OK.
-
Create a simple UI that includes two buttons and a
datagrid, as shown in the following graphic. Name the buttons
btnGetSales (set this button’s
Text property to Get
Sales) and btnExit (set
this button’s Text property to Exit). Change the
Name property of the datagrid to datagrdSales.
-
Double-click both buttons to create events in the
code-behind file.
-
Right-click Add Service Reference, and paste in the WCF service
URI you deployed to Windows Azure. Click Go to retrieve the
service definition, and then provide a name for the service
namespace (such as AzureDeployedService). Next, edit the
code-behind in the Windows application to match the bold code
here:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SalesTestApp.AzureDeployedService;
namespace SalesTestApp
{
public partial class Form1 : Form
{
SharePointCallingServiceClient proxy = new SharePointCallingServiceClient();
public Form1()
{
InitializeComponent();
}
private void btnGetSales_Click(object sender, EventArgs e)
{
var items = proxy.GetSales();
datagrdSales.DataSource = items;
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
-
To begin the test, launch the on-premises service by right-clicking it and selecting Debug,
| Start New Instance. This starts the listener service (that is,
the on-premises service).
-
Next, right-click the Windows Forms application, and then
select Debug | Start New Instance.
You should now have two applications running in debug mode:
the on-premises service and your Windows test application. If you
click the Get Sales button in your test application, you’ll see a
status message appear in the console application as
shown in Figure 9. (In the
figure, I’ve clicked the Get Sales button twice.) The service writes
this message to the console each time the WCF service deployed to
Windows Azure calls it.
When the service receives the call, it should successfully
execute the SharePoint code that pulls the data from the Sales
list and populates the datagrid with the returned data.
Testing with a Windows Forms application is one thing—you’re
on-premises and probably coding against the same server where
SharePoint is deployed. So you might not necessarily be impressed
just yet. However, next you’ll take it one level further and build a
remote application that leverages the Windows Azure WCF service to
call into the SharePoint site. In this next exercise, you’ll build a
Windows Phone 7 application that uses the service bus to get the on-premises data from the
SharePoint list and expose it on the phone emulator.
Because much of the Windows Phone 7 development is done on a client machine, you might
need to work on a separate Windows 7 machine. Setting up your
development environment for Windows Phone 7 development is amazingly
easy; just download the tools and free Express version of Visual
Studio from http://www.microsoft.com/express/phone/, and you’re
up and running.