Building Silverlight Bing Maps based API with Cloud application in SharePoint 2010


Developing Bing Maps API based Silverlight applications are quite easy integrating with Windows Azure , SQL Azure databases with Microsoft SharePoint 2010. Bing Maps API provides a rich set of geolocation APIs which helps to easy integrate with Silverlight, Windows Azure application.

  • To use Bing Maps with Silverlight Web applications , you need to get the Bing Maps Developer key which can be obtained from www.bingmapsportal.com , register there with your Windows Live ID & get a developer key by clicking on create or view key.

  •  Next, you need keep the key in clipboard & should be used while developing your Silverlight application. Now create a new Silverlight application from Visual Studio & modify the following XAML into it.

  • Write in MainPage.XAML :

<UserControl x:Class=”SimpleBingMap.MainPage”

xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;

xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;

xmlns:d=”http://schemas.microsoft.com/expression/blend/2008&#8243;

xmlns:m=”clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl”        

xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243;

mc:Ignorable=”d”

d:DesignHeight=”300″ d:DesignWidth=”400″>

<Grid x:Name=”LayoutRoot” Background=”White” HorizontalAlignment=”Stretch”

VerticalAlignment=”Stretch” Width=”888″ Height=”394″>

<Grid.ColumnDefinitions>

<ColumnDefinition Width=”888*” />

<ColumnDefinition Width=”314*” />

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition Height=”auto” />

<RowDefinition Height=”*” />

</Grid.RowDefinitions>

<StackPanel Grid.ColumnSpan=”2″>

<TextBlock Text=”Map Me!” FontWeight=”Bold” FontSize=”14″ Width=”888″ />

<StackPanel Orientation=”Horizontal” HorizontalAlignment=”Stretch” Margin=”12,0,12,0″>

<TextBox x:Name=”txtbxLatitude” Width=”322″ Text=”Type your latitude here,e.g. 47.7656″ FontSize=”10″ />

</StackPanel>

<StackPanel Orientation=”Horizontal” HorizontalAlignment=”Stretch” Margin=”12,0,12,0″>

<TextBox x:Name=”txtbxLongitude” Width=”322″ Text=”Type your longitude here, e.g. -122.9957″ FontSize=”10″ />

</StackPanel>

<StackPanel Orientation=”Horizontal” HorizontalAlignment=”Stretch” Margin=”12,0,12,0″>

<Button x:Name=”btnFindMe” Content=”Map It!” Width=”65″ Click=”btnFindMe_Click” />

</StackPanel>

</StackPanel>

<m:Map CredentialsProvider=”Av1a04p5K8Ubd97aV5dMMX7tRSbDxWz8hm01_4ZA8BA2kE7o56VvsNfjMOOrTnV5″ x:Name=”MyMap” Grid.Row=”1″ Mode=”AerialWithLabels” HorizontalAlignment=”Stretch” VerticalAlignment=”Stretch” Margin=”0,14,0,0″ Grid.ColumnSpan=”2″>

<m:Map.Children>

<m:MapLayer x:Name=”PushPinLayer” />

</m:Map.Children>

</m:Map>

</Grid>

</UserControl>

  • Write in 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.Maps.MapControl;


namespace SimpleBingMap

{

public partial class MainPage : UserControl

{

public MainPage()

{

InitializeComponent();

}

private  void btnFindMe_Click(object sender, RoutedEventArgs e)

{

Location myLocation = newLocation();

myLocation.Latitude = Double.Parse(txtbxLatitude.Text);

myLocation.Longitude = Double.Parse(txtbxLongitude.Text);

// Create a new pushpin to add to the map.

Pushpin myPPin = newPushpin();

myPPin.Width = 7;

myPPin.Height = 10;

myPPin.Location = myLocation;

PushPinLayer.AddChild(myPPin, myLocation, PositionOrigin.Center);

// Set the main view of the map using location with a zoom level

MyMap.SetView(myLocation, 10);

}

}

}

 

  • Map yourself in Bing Maps API by providing Latitude & Longitude:

  • Now, it’s time to integrate with your SharePoint 2010 website. Open the Add Documents Library option & Click on Add, Click browser & paste the path of Silverlight .xap file in SharePoint directory.
  • Click on Site Settings & Click on Edit Page to open the .xap file in SharePoint Web Part, Now open the insert tab-> Click on Media Content-> Silverlight Web Part -> paste the path of the Silverlight .xap file in the clipboard. Access it in Silverlight portal.

 

  • Configure the height & width according to configuration :

  • That’s it, The SharePoint applications is integrated with Silverlight web part along with Bing Maps API integrated in Cloud.

Consuming OData WCF REST service from Windows Phone 7 Panorama Application


Consuming an OData (Open Data Protocol) in Client devices , Client services are quite easy. Open Data protocol , is a web protocol for querying and updating data and it was born of the need to break down data silos and increase their shared value. This allows data silos to interoperate between producers such as SQL Server, SharePoint servers, Cloud Storage Services, and consumers, for example Java, PHP, Silverlight, IIS, ASP.NET, AJAX.

OData incorporates with JSON, AtomPub, RSS to provide access to the  information from a range of applications, services, relational databases, file systems, content management systems (CMS), traditional websites.

Supported Platforms for OData Services:

  1. Microsoft Visual Studio 2008 SP1
  2. Microsoft Visual Studio 2010
  3. Microsoft SQL Server 2008 R2
  4. Microsoft Sharepoint 2010
  5. Microsoft Windows Azure Storage(Blobs, Tables, Queues)
  6. Microsoft SQL Azure
  7. Microsoft Office Excel 2010 PowerPivot
  • Lets create an OData WCF REST Service that for this purpose lets create an empty web application from Visual Studio

  • Lets add a new WCF Service in the application & named it as Service.SVC

  • Next , add the following Code to the service & check the resulting feed in browser.

using System;

using System.Collections.Generic;

using System.Data.Services;

using System.Data.Services.Common;

using System.Linq;

using System.ServiceModel.Web;

using System.Web;


namespace ODataSample1

{

public class Service : DataService<SampleDataSource>

{

// This method is called only once to initialize service-wide policies.

public static void InitializeService(DataServiceConfiguration config)

{

// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.

// Examples:

// config.SetEntitySetAccessRule(“MyEntityset”, EntitySetRights.AllRead);

// config.SetServiceOperationAccessRule(“MyServiceOperation”, ServiceOperationRights.All);

config.SetEntitySetAccessRule(“*”, EntitySetRights.All);

config.SetServiceOperationAccessRule(“*”, ServiceOperationRights.All);

config.MaxResultsPerCollection = 100;

config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

}

}

EntityPropertyMappingAttribute(“CustomerName”, SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, true)]

[DataServiceKey(“CustomerID”)]

public class CustomerRecord

{

public int CustomerID { get; set; }

public string CustomerName { get; set; }

public string CustomerEmail { get; set; }

public string CustomerNotes { get; set; }

public DateTime CustomerLastContact { get; set; }

}

public class SampleDataSource

{

private readonly List<CustomerRecord> _sampleCustomerRecordList;

public SampleDataSource()

{

_sampleCustomerRecordList = newList<CustomerRecord>();

for (int i = 0; i < 100; i++)

{

CustomerRecord CR = newCustomerRecord();

CR.CustomerID = i;

CR.CustomerName =string.Format(“FirstName{0} LastName{1}”, i.ToString(), i.ToString());

CR.CustomerEmail =string.Format(“Email{0}@{1}.com”, i.ToString(), i.ToString());

CR.CustomerNotes =string.Format(“Notes{0}.Notes{1}”, i.ToString(), i.ToString());

CR.CustomerLastContact =DateTime.Now.AddDays(-10000).AddHours(i);

_sampleCustomerRecordList.Add(CR);

}

}

public IQueryable<CustomerRecord> SampleCustomerData

{

get

{

return _sampleCustomerRecordList.AsQueryable();

}

}

}

}

  • Now check the Service status in Linqpad (http://www.linqpad.com) by adding the WCF service endpoint to the database/service endpoint connection.

  • Lets check the status of the feed by entering query (<atom:title>)(e.g : SampleCustomerData  for this demo)in the browser

  •  Check after entering query in the URL of the feed

  • Service endpoint shows successful OData feed , next add a Windows Phone Panorama Application with the solution to implement a smartClient to the OData REST application.

datasvcutil /uri:http://localhost:8554/Service.svc/ /out:.\ServiceModel.cs /Version:2.0 /DataServiceCollection

<!–Panorama item one–>

<controls:PanoramaItem Header=”first item”>

<ListBox x:Name=”lst” Margin=”0,0,-12,0″ ItemsSource=”{Binding}”>

<ListBox.ItemTemplate>

<DataTemplate>

<StackPanel Margin=”0,0,0,17″ Width=”432″>

<TextBlock Text=”{Binding CustomerID}” TextWrapping=”Wrap” Margin=”12,-6,12,0″ Style=”{StaticResource PhoneTextExtraLargeStyle}” />

<TextBlock Text=”{Binding CustomerName}” TextWrapping=”Wrap” Margin=”12,-6,12,0″ Style=”{StaticResource PhoneTextExtraLargeStyle}” />

<TextBlock Text=”{Binding CustomerEmail}” TextWrapping=”Wrap” Margin=”12,-6,12,0″ Style=”{StaticResource PhoneTextExtraLargeStyle}” />

<TextBlock Text=”{Binding CustomerNotes}” TextWrapping=”Wrap” Margin=”12,-6,12,0″ Style=”{StaticResource PhoneTextExtraLargeStyle}” />

</StackPanel>

</DataTemplate>

</ListBox.ItemTemplate>

</ListBox>

</controls:PanoramaItem>

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 ODataWP7Panorama.CustomersModel;

using System.Data.Services.Client;

namespace ODataWP7Panorama

{

public partial classMainPage : PhoneApplicationPage

{

public  SampleDataSource ctx = new SampleDataSource(new Uri(http://localhost:8554/Service.svc/&#8221;, UriKind.Absolute));

// Constructor

public MainPage()

{

InitializeComponent();

this.Loaded += newRoutedEventHandler(MainPage_Loaded);

// Set the data context of the listbox control to the sample data

}

// Load data for the ViewModel Items

private void MainPage_Loaded(object sender, RoutedEventArgs e)

{

var ctx = newSampleDataSource(newUri(http://localhost:8554/Service.svc/));

var coll = new  DataServiceCollection<CustomerRecord>(ctx);

lst.ItemsSource = coll;

coll.LoadCompleted +=newEventHandler<LoadCompletedEventArgs>(coll_LoadCompleted);

var qry = “/SampleCustomerData”;

coll.LoadAsync(newUri(qry, UriKind.Relative));

}

void coll_LoadCompleted(object sender, LoadCompletedEventArgs e)

{

if (e.Error != null)

{

MessageBox.Show(e.Error.Message);

}

}

}

}

  • Now , lets the OData REST Service in Windows Phone 7.1 Client :

Accessing REST based service from Windows Phone 7.1 using SAML Token


Accessing REST based services from Windows Phone 7 client devices include two approaches: Active Federation implementation means how the client application uses OAuth protocol and contacts all the issuers in the trust chain in turn to acquire a valid SWT token to access a online enterprise application where as in passive federation mode device ‘s embedded browser requests the identity provider list from Access Control Service(ACS 2.0)  which in turn requests for token from trusted issuer & issuer sends back the SAML 2.0 token which is received by the device then it send a call to the enterprise REST service as Relying Party (RP) with Simple Web Token (SWT) Token.

  • Comparison of the Federation Difference:
  • The passive federation solution that leverages an embedded browser control offers a simpler approach to obtain an SWT token because the embedded web browser control in combination with the WS-Federation protocol handles most of the logic to visit the issuers and obtain the SWT token that the enterprise application needs.
  • In the active federation solution, the Windows Phone Application must include code to control the interactions with the issuers explicitly. Also, the active solution must include code to handle the requests for SAML tokens from the Relying Party(Issuer).
  • An advantage of passive federation approach is that it enables the Windows Phone Application to dynamically build the list of identity providers to your ACS configuration.
  • You must explicitly add any SWT token caching behavior to the Windows Phone application for both the active or passive federation solutions.
  • Download 9WindowsPhoneClientFederation from http://claimsid.codeplex.com to get Visual Studio development system  solution for Claims identity based REST services for Windows Phone .

Windows Azure Claims based Identity & Access Control ebook available


Most enterprise applications include a certain amount of logic that supports Identity -related features. Applications that can’t rely on Integrated Windows Authentication tend to have more of this than appeared to do. For example : web based applications that store usernames & passwords must handle password reset, lockout and other issues. Enterprise facing applications that use integrated Windows Authentication can rely on the domain controller.

  • Claims based identity allows you to factor out the authentication logic from individual applications instead of application determining who the user is, it receives claims that identifies claims that identify the user.
  • Microsoft annouced the second release of Claims Based Idenity & Access Control Book from Patterns & Practices Team.

Download from here: http://www.microsoft.com/download/en/details.aspx?id=28362

  • For better explanation about SAML (Security Assertion Markup Language) Token 2.0, Simple Web Token (SWT) , Relying Party, Requesting Security Service (RST), Secure Token Service(STS) , ADFS (Active Directory Federation Server 2.0 Single Sign On ) issues with asp.net authentication & far more illustration about Windows Identity foundation 4.0 (WIF) , Identity Runtime, Web Resource Authorization Protocol 2.0 (WRAP) covered in this book.

  • Concise explanation about Claims based identity in Windows Azure Web , Access Control Service(ACS), Service Bus Queues, Claims based identity with Sharepoint 2010 integration, Federated authentication with Sharepoint with Access Control Service(ACS V2)

Migration of an Existing On-Premise ASP.NET 4.0 Web Application to Windows Azure Part – I


In this world of Cloud, it’s very necessary to run your enterprise business apps in Cloud & provide the solution of better scalability, elasticity , High Availability & 24*7 on features to your customers.

  • Windows Azure is Platform as a Service (PAAS) model which helps to upgrade us in such a service. In this article , an existing on-premise enterprise healthcare application has been migrated into cloud & hosted in Microsoft Data – Centers.
  • To start working with Microsoft Windows Azure in Visual Studio 2010, Download the Windows Azure SDK from Azure website.  http://www.microsoft.com/windowsazure/sdk
  •    Now , First load your existing enterprise asp.net 4.0 application into visual studio & then in the solution explorer of the project right click on the solution & click Add-> New Project.

  • Now Select a new Windows Azure Project & named it & save it in the same folder of your existing on-premise application.
  •  In the Roles folder of your Windows Azure Project , Right Click, select Add & choose Existing Web Role in Solution. 
  • Now, check your existing asp.net web application has been migrated as a WebRole in Windows Azure Project.  Next , Set up your Windows Azure hosting environment. During compilation of your Windows Azure application in your development machine , you may encounter the following error:
     
  • Resolution: To solve this error, Open Windows Azure SDK Command Prompt in elevated mode & run the following command.
C:\Program Files\Windows azure SDK\v1.3\bin\ DSINIT /SQLINSTANCE:YourSQLServerInstanceName /Forcecreate  
  • If you dont have .SQLEXPRESS  as default instance of your SQL Server instance then you can modify the command as
C:\Program Files\Windows azure SDK\v1.3\bin\ DSINIT/sqlInstance:. 
  •   Now , You will get the following prompt for initialization of  Azure Storage Emulator in development fabric.
  • Next , Build your complete project solution & run the Windows Azure Project with existing ASP.NET 4.0 web application. During the debugging you will see the compute emulator  & storage emulator in your local dev fabric .

  •  Check out your on-premise existing asp.net web application migrated to windows azure & running in azure compute emulator in local development fabric.

  • To deploy the application , right click on Azure Project & Click Publish & create package (.cspkg ).
    
  • Now, select the radio button of Create Service Package Only otherwise select the second option if you would like to configure your Windows Azure Hosted service details in Visual Studio.
  • Build the Azure Service Package File (.cspkg) & Service Configuration (.cscfg) in Windows Explorer.
  • Next , Log on Windows Azure Developer portal with Windows Live ID with valid Azure Subscription & continue deployment.

Windows Azure Toolkit for Windows 8


The Windows Azure Toolkit for Windows 8 is released to make development easy for Windows Metro style application that can harness the power of Windows Azure Compute and Storage. The template is based on Windows Push Notification services existing with Windows Phone 7 applications.

Technologies:

  • ASP.NET MVC 3
  • Windows Azure SDK 1.4.1 Refresh
  • Windows Metro style Javascript application project

The process of sending a notification requires few steps:

  1. Request a channel. Utilize the WinRT API to request a Channel Uri from WNS. The Channel Uri will be the unique identifier you use to send notifications to an application instance.
  2. Register the channel with your Windows Azure cloud services. Once you have your channel you can then store your channel and associate it with any application specific data (e.g user profiles and such) until your services decide that it’s time to send a notification to the given channel
  3. Authenticate against WNS. To send notifications to your channel URI you are first required to Authenticate against WNS using OAuth2 to retrieve a token to be used for each subsequent notification that you push to WNS.
  4. Push notification to channel recipient. Once you have your channel, notification payload and WNS access token you can then perform an HttpWebRequest to post your notification to WNS for delivery to your client.

This slideshow requires JavaScript.

%d bloggers like this: