Consume a Windows Azure Service using Windows Phone 7

by Jagadish Pulakhandam on 12/28/2011 7:16:55 AM
Rated 0 from 0 votes
Brief: Video demonstration on how to consume a Windows Azure Service using Windows Phone 7
Posted to: Microsoft Azure Technologies
Add to DiggAdd to del.icio.usAdd to FURLAdd to RedditAdd to YahooAdd to BlinklistAdd to GoogleAdd to ma.gnoliaAdd to ShadowsAdd to Technorati

Attached video demonstrates the following:
  • Creating a new Windows Phone 7 application (from the scratch) using Visual Studio 2010
  • Adding a service reference to a hosted Windows Azure service (developed and deployed in previous posts)
  • Creating instance to proxy and accessing the service operations
NOTE:  Developing and testing the service used in this demonstration is covered in previous post.

Screenshot:



Source Code:

MainPage.xaml

<phone:PhoneApplicationPage
    x:Class="WinPhoneAzSvcConsumer.MainPage"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
 
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
 
        <!--ContentPanel - place additional content here-->
        <Canvas x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock Canvas.Left="12" Canvas.Top="24" Height="41" Name="textBlock1" Text="Enter First No:" Width="130" />
            <TextBox Canvas.Left="159" Canvas.Top="6" Height="73" Name="txtFirst" Text="" Width="190" />
            <TextBlock Canvas.Left="12" Canvas.Top="89" Height="41" Name="textBlock2" Text="Enter Second No:" Width="130" />
            <TextBox Canvas.Left="159" Canvas.Top="70" Height="73" Name="txtSecond" Text="" Width="190" />
            <Button Canvas.Left="188" Canvas.Top="149" Content="Calculate" Height="76" Name="btnCalc" Width="161" Click="btnCalc_Click" />
        </Canvas>
    </Grid>
  
    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->
 
</phone:PhoneApplicationPage>

MainPage.xaml.cs

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;
 
namespace WinPhoneAzSvcConsumer
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }
 
        private void btnCalc_Click(object sender, RoutedEventArgs e)
        {
            var oSvcClient = new CalcSvcRef.Service1Client();
            int a = Convert.ToInt16(this.txtFirst.Text);
            int b = Convert.ToInt16(this.txtSecond.Text);
 
            oSvcClient.GetSumCompleted += new EventHandler<CalcSvcRef.GetSumCompletedEventArgs>(oSvcClient_GetSumCompleted);
            oSvcClient.GetSumAsync(a,b);
        }
 
        void oSvcClient_GetSumCompleted(object sender, CalcSvcRef.GetSumCompletedEventArgs e)
        {
            MessageBox.Show("Sum = " + Convert.ToString(e.Result));
        }
    }
}

ServiceReferences.ClientConfig

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
                    maxReceivedMessageSize="2147483647">
                    <security mode="None" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://calcsvc.cloudapp.net/Service1.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
                contract="CalcSvcRef.IService1" name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

Join the .NET Code Central Community and join the discussion!
Signing-up is FREE and quick. Do it now, we want to hear your opinion
0

Rated 0 from 0 votes ( login  to rate)
DotnetKicks DotnetKicksDe DotNetShoutout

Attachments / Source Code
You need to Login or Join for FREE to download the following

Video/Screen Recording (may not have audio narration/annotations)
You need to Login or Join for FREE to download the following