IT tutorials
 
Windows
 

Using the Windows Azure Service Bus with SharePoint (part 6) - Create a Test Windows Phone 7 Application

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/21/2012 9:38:33 AM

Create a Test Windows Phone 7 Application

  1. After installing the Windows Phone Express tools, open Visual Studio and select File | New Project.

  2. Select the Windows Phone 7 Application template, provide a name for the project (such as GetSPSalesData), and click OK.

  3. The default platform for Windows Phone 7 development is Silverlight.

  4. Open the MainPage.xaml file and drag a listbox and a button onto the designer surface. Name the listbox lstbxSalesData and the button btnGetSales.

  5. Amend the XAML code in the Windows Phone 7 UI as shown in bold here:

    <phone:PhoneApplicationPage
      x:Class="SharePointEmployeesApp.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
      xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      FontFamily="{StaticResource PhoneFontFamilyNormal}"
      FontSize="{StaticResource PhoneFontSizeNormal}"
      Foreground="{StaticResource PhoneForegroundBrush}"
      SupportedOrientations="Portrait" Orientation="Portrait"
      mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
      shell:SystemTray.IsVisible="True">
    <phone:PhoneApplicationPage.Resources>
      <DataTemplate x:Key="salesData">
        <Grid Width="Auto">
          <Grid.RowDefinitions>
            <RowDefinition Height="60"/>
            <RowDefinition Height="60"/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="140"></ColumnDefinition>
            <ColumnDefinition Width="140"></ColumnDefinition>
            <ColumnDefinition Width="140"></ColumnDefinition>
          </Grid.ColumnDefinitions>
          <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding companyName}"
            FontWeight="Bold" FontSize="20" Height="50"/>
          <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding companyContact}"
            FontWeight="Bold" FontSize="20" Height="50"/>
          <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding companyFY09Sales}"
            FontSize="20" Height="60"/>
          <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding companyFY10Sales}"
            FontSize="20" Height="60"/>
          <TextBlock Grid.Row="1" Grid.Column="2" Text="{Binding companyFY11Sales}"
            FontSize="20" Height="60"/>
        </Grid>
      </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    <Grid x:Name="LayoutRoot" Background="Transparent">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
      <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
        <TextBlock x:Name="ApplicationTitle" Text="SHAREPOINT SALES DATA"
          Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="sales data" Margin="-3,-8,0,0"
          Style="{StaticResource PhoneTextTitle1Style}"/>
      </StackPanel>
      <Grid x:Name="ContentGrid" Grid.Row="1">
        <Button Content="Get Sales" Height="72"
          HorizontalAlignment="Left" Margin="123,512,0,0"
          Name="btnGetSales"
          VerticalAlignment="Top" Width="226" Click="btnGetSales_Click" />
        <ListBox Height="371" HorizontalAlignment="Left"
          Margin="11,32,0,0"
          Name="lstbxSalesData" VerticalAlignment="Top" Width="460"
          ItemsSource="{Binding}"
          ItemTemplate="{StaticResource salesData}">
        </ListBox>
      </Grid>
    </Grid>
    </phone:PhoneApplicationPage>

    Although the UI has only two controls, note that there is a data template associated with the listbox. This template provides some structure and formatting to the returned data—the data from the SharePoint list. You could get fancier with the UI design, but this serves to illustrate the point. The only event tied to the UI is the btnGetSales_Click event, which triggers a call to the WCF service deployed to Windows Azure, which then retrieves the SharePoint on-premises data.

  6. Assuming that you’ve added the preceding code to your project file, your Visual Studio integrated development environment (IDE) UI should look similar to the following.

    image with no caption
  7. Because you’re using Silverlight, add the code-behind for this project to the MainPage.xaml.cs file. Before you do this, though, you’ll need to add a service reference to the Windows Azure WCF service. To do this, right-click the project, select Add Service Reference, paste the service URI into the Address field, and click Go—as shown here.

    image with no caption
  8. Provide a namespace for your service (such as AzureServiceForSharePoint) and click OK.

  9. Right-click the project and select Add | Class. Name the class Sales and click Add. Edit the code for your class to match the code in bold shown here. You’ll use this class for in-memory data management:

    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    
    namespace SharePointEmployeesApp
    {
        public class Sales
        {
            public string companyName { get; set; }
            public string companyContact { get; set; }
            public string companyFY09Sales { get; set; }
            public string companyFY10Sales { get; set; }
            public string companyFY11Sales { get; set; }
        }
    }
  10. Open the MainPage.xaml.cs file and amend the code in the file as shown in bold here:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using SharePointEmployeesApp.AzureServiceProxy;
    
    namespace SharePointEmployeesApp
    {
    public partial class MainPage : PhoneApplicationPage
    {
       List<Sales> listOfSalesData = new List<Sales>();
       public MainPage()
       {
          InitializeComponent();
       }
       private void btnGetSales_Click(object sender, RoutedEventArgs e)
       {
          SharePointCallingServiceClient mySvcProxy = new
             SharePointCallingServiceClient();
             mySvcProxy.GetSalesCompleted += new
             EventHandler<GetSalesCompletedEventArgs>(mySvcProxy_GetSalesCompleted);
             mySvcProxy.GetSalesAsync();
       }
       void mySvcProxy_GetSalesCompleted(object sender, GetSalesCompletedEventArgs e)
       {
          if (e.Error == null)
          {
              var returnEmployeeData = e.Result;
              foreach (var item in returnEmployeeData)
              {
                 Sales tempSalesInfo = new Sales();
                 tempSalesInfo.companyName = item.Company.ToString();
                 tempSalesInfo.companyContact = item.Contact.ToString();
                 tempSalesInfo.companyFY09Sales = item.FY09Sales.ToString();
                 tempSalesInfo.companyFY10Sales = item.FY10Sales.ToString();
                 tempSalesInfo.companyFY11Sales = item.FY11Sales.ToString();
                 listOfSalesData.Add(tempSalesInfo);
              }
              lstbxSalesData.DataContext = listOfSalesData;
          }
          else
          {
             MessageBox.Show(e.Error.ToString());
          }
         }
       }
    }

    The preceding code manages the call to the WCF service you deployed to Windows Azure. The proxy (mySvcProxy) needs to be called asynchronously because you’re using Silverlight. Thus, you have two events that manage the service call: mySvcProxy.GetSalesAsync and mySvcProxy.GetSalesCompleted. You take the results using a var object (returnEmployeeData) and e.Result and create a list collection (listOfSalesData), which is then bound to a formatted listbox. Although the DataContext property is used in the code-behind, you can see in the earlier UI code that each of the textblocks is bound to properties in the custom Sales class.

After you’ve added the code, you’re ready to build and test the Windows Phone 7 application.

Press F5 to run the emulator. It might take a minute for the emulator to start if this is the first time you’ve created a Windows Phone 7 application. After the emulator starts, click the Get Sales button, and you’ll see data returned from the on-premises service (accessed via the WCF service) and then displayed in the data-bound listbox, as shown in Figure 11.

The Windows Phone 7 application remotely interacting with SharePoint data.

Figure 11. The Windows Phone 7 application remotely interacting with SharePoint data.

Windows Phone 7 applications are but one example of remote applications that you could use to access on-premises SharePoint data by using the AppFabric service bus. You can also create Silverlight applications and deploy them into SharePoint Online (Office 365), which will enable you to connect your cloud instance of SharePoint with your on-premises instances of SharePoint data. There are also many other types of web applications that cut across Microsoft ASP.NET, PHP, Java, and other platforms and devices (including Apple iPhone, Apple iPad, Android, and more) where you can use this pattern to interconnect cloud and on-premises data and systems.

 
Others
 
- Using the Windows Azure Service Bus with SharePoint (part 5) - Create a Test Windows Forms Application
- Using the Windows Azure Service Bus with SharePoint (part 4) - Create a WCF Service to Call the On-Premises Service
- Using the Windows Azure Service Bus with SharePoint (part 3) - Create an On-Premises Service
- Using the Windows Azure Service Bus with SharePoint (part 2) - Create the Listener Service
- Using the Windows Azure Service Bus with SharePoint (part 1) - Create a Service Bus Namespace
- Windows 8 : Working with User Accounts (part 3) - Switching Users
- Windows 8 : Working with User Accounts (part 2) - Changing User Account Settings
- Windows 8 : Working with User Accounts (part 1) - Add a User
- Mac OS X Hints
- Securing Your Windows 8 Computer : Maintaining Your Privacy
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us