<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>NickSwan</title>
        <link>http://www.lightningtools.com/blog/category/15.aspx</link>
        <description>NickSwan</description>
        <language>en-GB</language>
        <copyright>Lightning Tools</copyright>
        <managingEditor>support@lightningtools.com</managingEditor>
        <generator>Subtext Version 1.9.5.177</generator>
        <item>
            <title>CRM 2011 Online and SharePoint 2010 Integration through Business Connectivity Services</title>
            <link>http://lightningtools.com/blog/archive/2012/02/20/crm-2011-online-and-sharepoint-2010-integration-through-business-connectivity.aspx</link>
            <description>&lt;p&gt;Integrating SharePoint and Microsoft CRM makes sense. Your sales team use CRM as they go about their daily work, but quite often non-sales people still need to be able to access and work with the same data. Although CRM 2011 has become part of the Office 365 package recently, they still run as separate instances in the cloud. Getting the data from CRM 2011 online displayed in SharePoint Online through the Business Connectivity Services is possible but needs a bit of coding and Azure magic. We are going to go through the steps to show you the kind of things involved to get this to happen. The scenario is we want to be able to display 30 days worth of orders in SharePoint Online through the Business Connectivity Services.&lt;/p&gt;  &lt;p&gt;This post makes a number of assumptions:&lt;/p&gt;  &lt;p&gt;1, You have an Azure account setup and the tools installed with Visual Studio 2010.&lt;/p&gt;  &lt;p&gt;2, You know how to deploy a project to Azure&lt;/p&gt;  &lt;p&gt;3, You have a CRM 2011 Online account and a SharePoint Online account (may be both are through Office 365)&lt;/p&gt;  &lt;p&gt;4, You have downloaded the &lt;a href="http://www.microsoft.com/download/en/details.aspx?id=24004" target="_blank"&gt;CRM 2011 SDK&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Here’s an overview of what we are going to do:&lt;/p&gt;  &lt;p&gt;1, Build a WCF Service that can pull data from CRM Online and present it in a BCS friendly manner&lt;/p&gt;  &lt;p&gt;2, Run this WCF Service on Azure&lt;/p&gt;  &lt;p&gt;3, Use SharePoint Designer 2010 to create an External Content Type that will display CRM data in SharePoint Online.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Generate Early Bound Types for CRM&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Crm has a really flexible data model which allows you to add new custom fields to entities such as customers or sales. This also presents the problem that the web services are not strongly typed. There are some web service methods you can call to discover the data structure that is used within CRM, but Microsoft also ships a tool with the CRM SDK that can generate your CRM data model in code so you can use Linq to CRM to get access to your data. &lt;/p&gt;  &lt;p&gt;Open a command prompt and move to the bin folder within the CRM SDK. crmsvcutil.exe is the tool we use to generate our code. At the command prompt type:&lt;/p&gt;  &lt;p&gt;CrmSvcUtil.exe /url:https://[YourCrmSiteName].crm.dynamics.com/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /username:"[your Live Id]" /password:"[your password]"&lt;/p&gt;  &lt;p&gt;These are the parameters you need to use when using CRM 2011 online. If you are using CRM on premise or have any issues running this check out this page for some help:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/gg327844.aspx"&gt;http://msdn.microsoft.com/en-us/library/gg327844.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Running the command above will generate a file called GeneratedCode.cs that we will add to our project shortly.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Create a WCF Azure Service&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;1, Open up Visual Studio 2010 and choose to Create a new Cloud –&amp;gt; Windows Azure Project called something like CrmBcsWcfLayer (see how many acronyms I can fit into a project name! &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/wlEmoticon-smile_2.png" /&gt;)&lt;/p&gt;  &lt;p&gt;2, Select the WCF Service Web Role from the Azure project types available and once moved across to the right pane hover your mouse over it to rename it to something sensible&lt;/p&gt;  &lt;p&gt;3, First thing we can do is add our GeneratedCode.cs file from earlier into our WCF project. This file is generated in the same directory where you ran the crmsvcutil tool.&lt;/p&gt;  &lt;p&gt;4, Now we need to add some assembles from the CRM SDK. In the bin folder of the SDK select:&lt;/p&gt;  &lt;p&gt;microsoft.xrm.sdk    &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;Also add a reference to:&lt;/p&gt;  &lt;p&gt;System.Security&lt;/p&gt;  &lt;p&gt;5, To help us authenticate and run code against CRM Online we want to make use of a helper class from the CRM SDK. Add an existing item to your project and find \{YOUR CRM SDK}\sdk\samplecode\cs\helpercode\deviceidmanager.cs&lt;/p&gt;  &lt;p&gt;6, Open up IService.cs and delete the CompositeType class. The SalesOrder CRM object has many fields, but we only want to return a small subset. We will therefore define our own class that contains this subset of fields&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:cd994524-98bc-44db-ad29-9c033a7ac0ae" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;;font-family:Consolas;font-size:11.25"&gt;&lt;span style="color: #000000;"&gt;[DataContract]
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; BcsSalesOrder
{
    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; Guid SalesOrderId { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }

    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;decimal&lt;/span&gt;&lt;span style="color: #000000;"&gt; TotalAmount { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }

    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; CustomerName { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }

    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; DateTime OrderDate { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }
}&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;7, Still in IService.cs, delete the two old operation contracts from there. Add in the following interface&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:45ebff89-05d0-4d0a-a867-b4c0cefe7a7c" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;;font-family:Consolas;font-size:11.25"&gt;&lt;span style="color: #000000;"&gt;[OperationContract]
IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;BcsSalesOrder&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetRecentOrders();
        &lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;8, Right click on Service1.svc and chose View Code. Clear out the GetData and GetDataUsingDataContract method.&lt;/p&gt;

&lt;p&gt;9, We’re going to add some code to help us Authenticate against CRM. This code is taken from samples in the CRM ask so I can’t take any credit for it! Within the Service1 class paste in:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d54ea898-3bcc-4408-8487-bc7118afcf66" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;;font-family:Consolas;font-size:11.25"&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; Obtain the AuthenticationCredentials based on AuthenticationProviderType.
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;param name="endpointType"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;An AuthenticationProviderType of the CRM environment.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;Get filled credentials.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;span style="color: #808080;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; AuthenticationCredentials GetCredentials(AuthenticationProviderType endpointType)
{

    AuthenticationCredentials authCredentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; AuthenticationCredentials();
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;switch&lt;/span&gt;&lt;span style="color: #000000;"&gt; (endpointType)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;case&lt;/span&gt;&lt;span style="color: #000000;"&gt; AuthenticationProviderType.ActiveDirectory:
            authCredentials.ClientCredentials.Windows.ClientCredential &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; System.Net.NetworkCredential(_userName,
                    _password,
                    _domain);
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;break&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;case&lt;/span&gt;&lt;span style="color: #000000;"&gt; AuthenticationProviderType.LiveId:
            authCredentials.ClientCredentials.UserName.UserName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; _userName;
            authCredentials.ClientCredentials.UserName.Password &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; _password;
            authCredentials.SupportingCredentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; AuthenticationCredentials();
            authCredentials.SupportingCredentials.ClientCredentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
                Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;break&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;default&lt;/span&gt;&lt;span style="color: #000000;"&gt;: &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; For Federated and OnlineFederated environments.                    &lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;            authCredentials.ClientCredentials.UserName.UserName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; _userName;
            authCredentials.ClientCredentials.UserName.Password &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; _password;
            &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; For OnlineFederated single-sign on, you could just use current UserPrincipalName instead of passing user name and password.
            &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; authCredentials.UserPrincipalName = UserPrincipal.Current.UserPrincipalName;  &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt;Windows/Kerberos&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;break&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    }

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; authCredentials;
}

&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; Discovers the organizations that the calling user belongs to.
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;param name="service"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;A Discovery service proxy instance.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;Array containing detailed information on each organization that 
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; the user belongs to.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;span style="color: #808080;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; OrganizationDetailCollection DiscoverOrganizations(
    IDiscoveryService service)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (service &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;null&lt;/span&gt;&lt;span style="color: #000000;"&gt;) &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ArgumentNullException(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;service&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
    RetrieveOrganizationsRequest orgRequest &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; RetrieveOrganizationsRequest();
    RetrieveOrganizationsResponse orgResponse &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        (RetrieveOrganizationsResponse)service.Execute(orgRequest);

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; orgResponse.Details;
}

&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; Finds a specific organization detail in the array of organization details
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; returned from the Discovery service.
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;param name="orgFriendlyName"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;The friendly name of the organization to find.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;param name="orgDetails"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;Array of organization detail object returned from the discovery service.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;Organization details or null if the organization was not found.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;seealso cref="DiscoveryOrganizations"/&amp;gt;&lt;/span&gt;&lt;span style="color: #808080;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; OrganizationDetail FindOrganization(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; orgFriendlyName,
    OrganizationDetail[] orgDetails)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (String.IsNullOrWhiteSpace(orgFriendlyName))
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ArgumentNullException(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;orgFriendlyName&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (orgDetails &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;null&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ArgumentNullException(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;orgDetails&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
    OrganizationDetail orgDetail &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;null&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;foreach&lt;/span&gt;&lt;span style="color: #000000;"&gt; (OrganizationDetail detail &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; orgDetails)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (String.Compare(detail.FriendlyName, orgFriendlyName,
            StringComparison.InvariantCultureIgnoreCase) &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
        {
            orgDetail &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; detail;
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;break&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
        }
    }
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; orgDetail;
}

&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; Generic method to obtain discovery/organization service proxy instance.
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;typeparam name="TService"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; Set IDiscoveryService or IOrganizationService type to request respective service proxy instance.
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;typeparam name="TProxy"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; Set the return type to either DiscoveryServiceProxy or OrganizationServiceProxy type based on TService type.
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;param name="serviceManagement"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;An instance of IServiceManagement&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;param name="authCredentials"&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;The user's Microsoft Dynamics CRM logon credentials.&lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #808080;"&gt;///&lt;/span&gt;&lt;span style="color: #008000;"&gt; &lt;/span&gt;&lt;span style="color: #808080;"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;span style="color: #808080;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; TProxy GetProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TService, TProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(
    IServiceManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; serviceManagement,
    AuthenticationCredentials authCredentials)
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;where&lt;/span&gt;&lt;span style="color: #000000;"&gt; TService : &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;where&lt;/span&gt;&lt;span style="color: #000000;"&gt; TProxy : ServiceProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
{
    Type classType &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(TProxy);

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (serviceManagement.AuthenticationType &lt;/span&gt;&lt;span style="color: #000000;"&gt;!=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        AuthenticationProviderType.ActiveDirectory)
    {
        AuthenticationCredentials tokenCredentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            serviceManagement.Authenticate(authCredentials);
        &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Obtain discovery/organization service proxy for Federated, LiveId and OnlineFederated environments. 
        &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Instantiate a new class of type using the 2 parameter constructor of type IServiceManagement and SecurityTokenResponse.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; (TProxy)classType
            .GetConstructor(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Type[] { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(IServiceManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;), &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(SecurityTokenResponse) })
            .Invoke(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;object&lt;/span&gt;&lt;span style="color: #000000;"&gt;[] { serviceManagement, tokenCredentials.SecurityTokenResponse });
    }

    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Obtain discovery/organization service proxy for ActiveDirectory environment.
    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Instantiate a new class of type using the 2 parameter constructor of type IServiceManagement and ClientCredentials.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; (TProxy)classType
        .GetConstructor(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Type[] { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(IServiceManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;TService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;), &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(ClientCredentials) })
        .Invoke(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;object&lt;/span&gt;&lt;span style="color: #000000;"&gt;[] { serviceManagement, authCredentials.ClientCredentials });
}&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;You’ll need to resolve some references once you paste this code in.&lt;/p&gt;

&lt;p&gt;10, In Service1.svc we need to add a few class variables that we’ll set…&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9ad3e3ee-e0b3-47ae-9177-35e496f5fd18" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;;font-family:Consolas;font-size:11.25"&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; String _discoveryServiceAddress &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; String _organizationUniqueName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Provide your user name and password.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; String _userName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Live Id&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; String _password &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Password&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

&lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Provide domain name for the On-Premises org.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; String _domain &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;mydomain&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Set the values for your Organization name, and the Live Id and password you want to connect as.&lt;/p&gt;

&lt;p&gt;11, Add in the method that was defined in our interface:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b95e4775-dd76-4033-9a72-b43f6af5bc18" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;;font-family:Consolas;font-size:11.25"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;BcsSalesOrder&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetRecentOrders()
{

}&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;12, Add in the following code to this method:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:1a2a26a8-55f2-4b79-b6a3-32e0c6285603" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;;font-family:Consolas;font-size:11.25"&gt;&lt;span style="color: #000000;"&gt;List&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;BcsSalesOrder&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; orders &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; List&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;BcsSalesOrder&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;();

IServiceManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IDiscoveryService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; serviceManagement &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            ServiceConfigurationFactory.CreateManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IDiscoveryService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(
            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Uri(_discoveryServiceAddress));
AuthenticationProviderType endpointType &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; serviceManagement.AuthenticationType;

&lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Set the credentials.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;AuthenticationCredentials authCredentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetCredentials(endpointType);


String organizationUri &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; String.Empty;
&lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Get the discovery service proxy.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;using&lt;/span&gt;&lt;span style="color: #000000;"&gt; (DiscoveryServiceProxy discoveryProxy &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    GetProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IDiscoveryService, DiscoveryServiceProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(serviceManagement, authCredentials))
{
    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Obtain organization information from the Discovery service. &lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (discoveryProxy &lt;/span&gt;&lt;span style="color: #000000;"&gt;!=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;null&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
    {
        &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Obtain information about the organizations that the system user belongs to.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;        OrganizationDetailCollection orgs &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; DiscoverOrganizations(discoveryProxy);
        &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Obtains the Web address (Uri) of the target organization.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;        organizationUri &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; FindOrganization(_organizationUniqueName,
            orgs.ToArray()).Endpoints[EndpointType.OrganizationService];

    }
}


&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (&lt;/span&gt;&lt;span style="color: #000000;"&gt;!&lt;/span&gt;&lt;span style="color: #000000;"&gt;String.IsNullOrWhiteSpace(organizationUri))
{
    IServiceManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IOrganizationService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; orgServiceManagement &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        ServiceConfigurationFactory.CreateManagement&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IOrganizationService&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Uri(organizationUri));

    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Set the credentials.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;    AuthenticationCredentials credentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetCredentials(endpointType);

    &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; Get the organization service proxy.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;using&lt;/span&gt;&lt;span style="color: #000000;"&gt; (OrganizationServiceProxy organizationProxy &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        GetProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IOrganizationService, OrganizationServiceProxy&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(orgServiceManagement, credentials))
    {
        &lt;/span&gt;&lt;span style="color: #008000;"&gt;//&lt;/span&gt;&lt;span style="color: #008000;"&gt; This statement is required to enable early-bound type support.&lt;/span&gt;&lt;span style="color: #008000;"&gt;
&lt;/span&gt;&lt;span style="color: #000000;"&gt;        organizationProxy.EnableProxyTypes();

        var service &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; (IOrganizationService)organizationProxy;
        OrganizationServiceContext orgContext &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; OrganizationServiceContext(service);

        IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;SalesOrder&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; crmOrders &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; from s &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; orgContext.CreateQuery&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;SalesOrder&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;()
                                            &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;where&lt;/span&gt;&lt;span style="color: #000000;"&gt; s.DateFulfilled.Value &lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; DateTime.Now.AddMonths(&lt;/span&gt;&lt;span style="color: #000000;"&gt;-&lt;/span&gt;&lt;span style="color: #800080;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
                                            select s;

        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;foreach&lt;/span&gt;&lt;span style="color: #000000;"&gt; (var salesOrder &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; crmOrders)
        {
                        
            var bcsOrder &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; BcsSalesOrder();
            bcsOrder.SalesOrderId &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; (Guid)salesOrder.SalesOrderId;
            bcsOrder.CustomerName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; salesOrder.CustomerId.Name;
            bcsOrder.OrderDate &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; Convert.ToDateTime(salesOrder.DateFulfilled);
            bcsOrder.TotalAmount &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; salesOrder.TotalAmount.Value;

            orders.Add(bcsOrder);
        }

    }
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; orders;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;13, We can now test our WCF service to make sure it can return some data from CRM Online. Press F5 in Visual Studio and once the browser opens copy out the url from the address bar. Then open a Visual Studio command prompt from the start menu and type wcftestclient.&lt;/p&gt;

&lt;p&gt;14, Once the WCF Test Client opens up go File –&amp;gt; Add a Service, and paste in your url&lt;/p&gt;

&lt;p&gt;15, Click on the GetThisMonthsOrders from the tree view in the right Window and then click the Invoke button. This will try to execute your WCF method and if successful you should see data returned in the bottom window:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/SNAGHTML41c7e1.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML41c7e1" border="0" alt="SNAGHTML41c7e1" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/SNAGHTML41c7e1_thumb.png" width="244" height="156" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you get an error returned, you should be able to step through the code in Visual Studio and fix it. If you do not get any data returned, make sure you have some orders in CRM that have been fulfilled in the last month.&lt;/p&gt;

&lt;p&gt;16, Now we can deploy this to Azure. Right click on the Azure project in Visual Studio and click Package&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_thumb.png" width="244" height="79" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will notice when you do this you get a warning about Microsoft.IdentityModel.dll being required. This is because microsoft.xrm.sdk has a dependancy on it. Follow the instructions in the Output console to add it as a reference to your project and also set it to ‘copy local’&lt;/p&gt;

&lt;p&gt;17, Once the Service Package file and Cloud Service Configuration File have been produced you can deploy this to Azure.&lt;/p&gt;

&lt;p&gt;18, Once your project has been deployed it is always a good thing to test it with the WcfTestClient again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting the data into SharePoint Online&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1, If you are at this stage then great! We can now get our data displaying in SharePoint Online. Open up SharePoint Designer and connect to your SharePoint Online site&lt;/p&gt;

&lt;p&gt;2, Click on the External Content Types button in the Site Objects listing&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_thumb_1.png" width="211" height="124" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3, Click the button in the ribbon to create a new External Content Type&lt;/p&gt;

&lt;p&gt;4, Give your External Content Type a nice name such as Orders, and then click on the link to use the Operation Designer:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_thumb_2.png" width="560" height="40" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5, Click the button to ‘Add a connection’ and choose the type to be WCF Service&lt;/p&gt;

&lt;p&gt;6, When viewing your service1.svc file running on Azure, you should see a link to the wsdl file. It’s basically the same as service1.svc but with ?wsdl on the end. Copy the whole url out and paste it into the Service Metadata Url field in SPD&lt;/p&gt;

&lt;p&gt;7, Put the normal service1.svc full url into Service Endpoint URL, and you can then click OK:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/SNAGHTML941779.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML941779" border="0" alt="SNAGHTML941779" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/SNAGHTML941779_thumb.png" width="171" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;8, With the Service Endpoint now displayed in the SPD connection manager, expand the tree so you can see the method we created and right click on it. Choose ‘New Read List Operation’ and step through the wizard. You do not actually need to change anything in the steps to get our simple example working except on the third screen select SalesOrderId as the Identifier for this ECT&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_thumb_3.png" width="244" height="116" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;9, Once the Operation Designer wizard has finished, click the Save button in the top left of SPD and your External Content Type will be created!&lt;/p&gt;

&lt;p&gt;10, The final step! Woot! Log on to SharePoint Online and add a Business Data List web part to the page. Configure it to use your Orders External Content Type:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_thumb_4.png" width="244" height="204" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;11, Click OK in the web part properties, and you should see Orders from your CRM system from the last 30 days (that the CRM users credentials you used in your WCF service have permission to see)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/CRM-2011-Online-and-SharePoint-2010-Busi_E936/image_thumb_5.png" width="644" height="162" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should be asking yourself right now – but this WCF web service is publically available and so anyone could call it and see my CRM data – and you are completely correct. As a ‘how-to’ article we are leaving things here, but if you were to be following this and using it as a basis for moving something into production you definitely need to consider how you will secure the WCF end point so only SharePoint Online and the BCS can call it. Steve Fox has a good blog post and a link to a lab to go through the different options around this, this should definitely be your next step:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/steve_fox/archive/2012/02/07/sharepoint-online-and-windows-azure-developing-secure-bcs-connections-using-wcf-services.aspx" target="_blank"&gt;SharePoint Online and Windows Azure: Developing Secure BCS Connections using WCF Services&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hopefully this post has given you a good introduction of the steps needed to get data from CRM 2011 Online displayed in SharePoint Online through the Business Connectivity Services. There are a few steps required to get this working, but the good news is we are working on some tools and services to make this a whole lot easier. If you’d like more information on these tools and be an early beta tester please drop me an email : &lt;a href="mailto:nick@lightningtools.com"&gt;nick@lightningtools.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;nick/&amp;gt;&lt;/p&gt;&lt;img src="http://lightningtools.com/blog/aggbug/313.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lightning Tools</dc:creator>
            <guid>http://lightningtools.com/blog/archive/2012/02/20/crm-2011-online-and-sharepoint-2010-integration-through-business-connectivity.aspx</guid>
            <pubDate>Mon, 20 Feb 2012 21:14:20 GMT</pubDate>
            <wfw:comment>http://lightningtools.com/blog/comments/313.aspx</wfw:comment>
            <comments>http://lightningtools.com/blog/archive/2012/02/20/crm-2011-online-and-sharepoint-2010-integration-through-business-connectivity.aspx#feedback</comments>
            <wfw:commentRss>http://lightningtools.com/blog/comments/commentRss/313.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using Twilio with SharePoint to send SMS messages</title>
            <link>http://lightningtools.com/blog/archive/2012/02/03/using-twilio-with-sharepoint-to-send-sms-messages.aspx</link>
            <description>&lt;p&gt;Twilio is a Software as a Service platform that you can use when you want to integrate voice or SMS text messages into your applications. There are a few instances where this could be interesting for SharePoint such as sending SMS messages when certain things happen in SharePoint either through event handlers or workflows. Let’s see how we can easily register for an account, setup a number and start getting SharePoint sending SMS messages using an Event Handler!&lt;/p&gt;  &lt;p&gt;1, Visit &lt;a href="http://www.twilio.com"&gt;www.twilio.com&lt;/a&gt; and click Try Twilio button – the good news is at the time of writing you get $30 of credit to try Twilio out!&lt;/p&gt;  &lt;p&gt;2, Once logged in click on the ‘Upgrade Now’ link to add a credit card to your Twilio account and add a small amount, say $20. You can’t purchase a phone number to send messages from with the trial account (you still get $30 free though once you upgrade)&lt;/p&gt;  &lt;p&gt;3, Once upgraded, click Numbers from the main menu and then the ‘Buy a new Twilio Number’ link.&lt;/p&gt;  &lt;p&gt;4, You can put in an area code if you like for your number to be based off, or if like me you are in the UK just press search and it will give you numbers to chose from with a London area code&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Buy a Twilio number" border="0" alt="Buy a Twilio number" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_6.png" width="244" height="173" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;[click the images for a larger view]&lt;/p&gt;  &lt;p&gt;5, Find the number you like the look of, and click the ‘Buy’ button to grab it! &lt;/p&gt;  &lt;p&gt;6, We need to get our AccountId and Password to use later on in our code. Click on the Dashboard link in Twilio. At the top you’ll see your AccountId, and if you click the padlock to the right your account password will also be displayed. Copy these down for later…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Get your Twilio account details" border="0" alt="Get your Twilio account details" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_7.png" width="411" height="68" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;7, The Twilio rest API all runs under https which is a good thing, but means a little extra configuration if you want to use it with SharePoint 2010. We’ll need to do an extra step of uploading the client certificate to SharePoint 2010 for SharePoint to trust the url. Open the following url in Firefox:&lt;/p&gt;  &lt;p&gt;&lt;a title="https://api.twilio.com/2010-04-01" href="https://api.twilio.com/2010-04-01"&gt;https://api.twilio.com/2010-04-01&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;8, Click on the Twilio icon in the address bar that indicates the certificate for this url is trusted&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Click the Twilio icon in Firefox" border="0" alt="Click the Twilio icon in Firefox" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb.png" width="138" height="60" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;9, In the panel that opens up click on the ‘More Information’ button:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Click the More Information button" border="0" alt="Click the More Information button" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_1.png" width="244" height="148" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;10, In the Page Information window that opens up click on ‘View Certificate’&lt;/p&gt;  &lt;p&gt;11, In the certificate viewer window move to the details tab, and then click the top line in the ‘Certificate Hierarchy’ window and then click the ‘Export’ button. This should allow you to save the certificate.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Export the Twilio certificate" border="0" alt="Export the Twilio certificate" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_2.png" width="204" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;12, Now we can add the certificate to SharePoint 2010. Open up Central Administration, Click on the Security Link and then ‘Manage Trust’.&lt;/p&gt;  &lt;p&gt;13, Click on the New button in the ribbon and a dialog form will pop up. Give the trust relationship a name of Twilio and browse to the certificate file you downloaded in step 10. Finally click on OK.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="In Central Administration add the certificate" border="0" alt="In Central Administration add the certificate" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_3.png" width="244" height="221" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;14, Hurrah – now we can start writing some code. Open up Visual Studio 2010 and create a new SharePoint 2010 Event Receiver project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Create a new SharePoint Event Receiver project" border="0" alt="Create a new SharePoint Event Receiver project" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_4.png" width="244" height="170" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;15, In the proceeding windows that show as part of creating your Visual Studio project chose to deploy it as a Farm Solution.&lt;/p&gt;  &lt;p&gt;16, When setting up the event receiver, pick List Item Events, the Announcement list type and finally the ‘An item was added’ event type – then click Finish&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Connect to the announcement list and the added event" border="0" alt="Connect to the announcement list and the added event" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/Using-Twilio-with-SharePoint_C626/image_thumb_5.png" width="244" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;17, Open EventReceiver1.cs and paste in the following code:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:025a1056-47cf-4c50-9878-24bb63094afa" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; CreateFormattedPostRequest(Dictionary&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; values)
{
    var paramterBuilder &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; StringBuilder();
    var counter &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;foreach&lt;/span&gt;&lt;span style="color: #000000;"&gt; (var value &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; values)
    {
        paramterBuilder.AppendFormat(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;{0}={1}&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, value.Key, HttpUtility.UrlEncode(value.Value));

        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (counter &lt;/span&gt;&lt;span style="color: #000000;"&gt;!=&lt;/span&gt;&lt;span style="color: #000000;"&gt; values.Count &lt;/span&gt;&lt;span style="color: #000000;"&gt;-&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800080;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;)
        {
            paramterBuilder.Append(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
        }

        counter&lt;/span&gt;&lt;span style="color: #000000;"&gt;++&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    }

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; paramterBuilder.ToString();
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;private&lt;/span&gt;&lt;span style="color: #000000;"&gt; HttpWebRequest CreateWebRequest(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; endPoint, Int32 contentLength)
{
    var request &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; (HttpWebRequest)WebRequest.Create(endPoint);

    request.Method &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;POST&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    request.ContentLength &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; contentLength;
    request.ContentType &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;application/x-www-form-urlencoded&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; request;
}  &lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;These two small helper methods will help us format out rest requests to the Twilio rest web service. &lt;a href="http://devlicio.us/blogs/derik_whittaker/archive/2009/02/14/posting-data-to-a-rest-service-using-c.aspx" target="_blank"&gt;Thanks to Derik for these two sections of code…&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;18, Add the following code to your ItemAdded method &lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f101b18d-7df2-458a-9dcb-74b9c57d4b05" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; accountId &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; password &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; from &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; to &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; title &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; properties.ListItem[&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Title&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;].ToString();

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; endPoint &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;.Format(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;https://api.twilio.com/2010-04-01/Accounts/{0}/SMS/Messages.xml&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, accountId);


Dictionary&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; parameters &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; Dictionary&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;();
parameters.Add(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;From&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, from);
parameters.Add(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;To&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, to);
parameters.Add(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Body&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, title);

var populatedEndPoint &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; CreateFormattedPostRequest(parameters);
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;byte&lt;/span&gt;&lt;span style="color: #000000;"&gt;[] bytes &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; Encoding.UTF8.GetBytes(populatedEndPoint);

HttpWebRequest request &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; CreateWebRequest(endPoint, bytes.Length);

request.Credentials &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; NetworkCredential(accountId, password);

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;using&lt;/span&gt;&lt;span style="color: #000000;"&gt; (var requestStream &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; request.GetRequestStream())
{
    requestStream.Write(bytes, &lt;/span&gt;&lt;span style="color: #800080;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;, bytes.Length);
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;using&lt;/span&gt;&lt;span style="color: #000000;"&gt; (var response &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; (HttpWebResponse)request.GetResponse())
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt; (response.StatusCode &lt;/span&gt;&lt;span style="color: #000000;"&gt;!=&lt;/span&gt;&lt;span style="color: #000000;"&gt; HttpStatusCode.Created)
    {
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; message &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; String.Format(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;POST failed. Received HTTP {0}&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, response.StatusCode);
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;throw&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ApplicationException(message);
    }
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;base&lt;/span&gt;&lt;span style="color: #000000;"&gt;.ItemAdded(properties);&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Set the values of accountId and password to the values we got in step 6. The value for ‘from’ should be the number you bought at Twilio, and the ‘to’ value is the number you want to send an SMS to.&lt;/p&gt;

&lt;p&gt;19, Tada – we are good to go. Press F5 and Visual Studio will compile and deploy your event receiver to SharePoint. If you do not have an Announcements list at the site Visual Studio opens up simply create one. Then go ahead and add an announcement and wait for the SMS text message to come through! Woot!&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Hopefully this has given you a taster to see how easy it is to use Twilio to send SMS text messages from SharePoint. If you have any other ideas how this service would be useful with SharePoint leave them in the comments!&lt;/p&gt;

&lt;p&gt;&amp;lt;&lt;a href="http://www.twitter.com/nickswan" target="_blank"&gt;nickswan&lt;/a&gt;/&amp;gt;&lt;/p&gt;&lt;img src="http://lightningtools.com/blog/aggbug/311.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lightning Tools</dc:creator>
            <guid>http://lightningtools.com/blog/archive/2012/02/03/using-twilio-with-sharepoint-to-send-sms-messages.aspx</guid>
            <pubDate>Fri, 03 Feb 2012 10:04:45 GMT</pubDate>
            <wfw:comment>http://lightningtools.com/blog/comments/311.aspx</wfw:comment>
            <comments>http://lightningtools.com/blog/archive/2012/02/03/using-twilio-with-sharepoint-to-send-sms-messages.aspx#feedback</comments>
            <wfw:commentRss>http://lightningtools.com/blog/comments/commentRss/311.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Mobile solutions for on premise data with Azure Service Bus</title>
            <link>http://lightningtools.com/blog/archive/2012/01/23/mobile-solutions-for-on-premise-data-with-azure-service-bus.aspx</link>
            <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note: &lt;/u&gt;I’m learning about Azure and Mobile Web App development as I go along. If you see any mistakes or better ways of doing things please drop me an email : &lt;a href="mailto:nick@lightningtools.com"&gt;nick@lightningtools.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;With more people becoming mobile workers, or working from home - business data that is stored away in on premise databases needs to be set free for people to use wherever they are, on whatever device they like. Accomplishing this can be a challenge for any size organization, opening firewall ports, active directory federated services, WCF service endpoints etc...&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Setting the data free&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;If you have an on premise data source that you want to make available to mobile workers you do have a number of options:&lt;/p&gt;  &lt;p&gt;1, SharePoint 2010, BCS + SharePoint Workspace    &lt;br /&gt;This is good for users who may not always have Internet connectivity as they can work offline and resync&lt;/p&gt;  &lt;p&gt;2, Present the data to the outside world through a WCF service hosted on premise.    &lt;br /&gt;This does mean exposing parts of the network to the outside world and needing to manage authentication to the WCF service. Certainly not impossible, but it does present challenges and risks.&lt;/p&gt;  &lt;p&gt;3, Using bits and pieces now available in Windows Azure    &lt;br /&gt;Using the Service Bus, we can expose the data through the firewall without needing to open up any extra ports. The authentication and security is managed through Azure Service Bus and ACS.&lt;/p&gt;  &lt;p&gt;I'm presuming we are working with a business that does not want to configure and setup ADFSv2. With many companies these days allowing employees to buy and use their own mobile or tablet devices managing these internally becomes a challenge.&lt;/p&gt;  &lt;p&gt;The actual data presentation solution will be an ASP.NET MVC web application running on Windows Azure. We'll use the jQueryMobile javascript library to present the data in a nice mobile looking way. This saves us having to build separate mobile applications for iPhone, Windows Phone, Android etc... Also having it as a web application allows us to easily rollout changes rather than expecting users to manually upgrade a native application.&lt;/p&gt;  &lt;p&gt;We'll use a simple example. In our company we have a product stock control system, and our people on the road need to be able to check the stock levels before placing an order. Working with a simple Products table:&lt;/p&gt;  &lt;p&gt;ProductId - int, primary key    &lt;br /&gt;Name - varchar(256)     &lt;br /&gt;Price – money     &lt;br /&gt;StockLevel - int&lt;/p&gt;  &lt;p&gt;We will use the Azure Service Bus to allow on premise data to be made available to the outside world. The Service Bus has 2 endpoints. The Listener endpoints will sit inside the organization, constantly running and listening for calls to execute methods that return data. The second component is a caller application, that calls the Listener methods over the service bus. The service bus makes sure the connection between the caller and listener are secure.&lt;/p&gt;  &lt;p&gt;Assumption : this walk through assumes you already have an Azure account up and running, with the necessary Azure SDK's and tools installed. To get an account setup and download the tools you need visit &lt;a href="http://www.azure.com" target="_blank"&gt;www.azure.com&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;u&gt;Configure the Service Bus&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;1, Log in to &lt;a href="http://www.azure.com/"&gt;www.azure.com&lt;/a&gt; and click the Manage button to open up the management portal.&lt;/p&gt;  &lt;p&gt;2, Once in the management portal, click on the 'Service Bus, Access Control &amp;amp; Caching' tab&lt;/p&gt;  &lt;p&gt;3, Click on the 'New' button within the 'Service Namespace' section&lt;/p&gt;  &lt;p&gt;4, Give the new service bus you want to create a name, such as MobileProducts and select a location for the ServiceBus to run that makes sense geographically&lt;/p&gt;  &lt;p&gt;5, Once your Service Bus is successfully created, click on the MobileProducts name in the list of buses available. This will display a list of properties down the right side.&lt;/p&gt;  &lt;p&gt;6, Click on the 'View' button in the 'Default Key' section. Listed in the pop up you shall see the Default Issuer and Default Key that you will need shortly.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Create a Model project&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;1, Open Visual Studio 2010 and create a new blank solution called MobileProducts. Add a new Class Library project to the solution called MobileProducts.Model. The target Framework should be .NET 4.0&lt;/p&gt;  &lt;p&gt;The Listener and Calling projects need to understand what object is being passed over the service bus, so it makes sense to create a project where you will define all these objects in classes in a central place where they can be referenced.&lt;/p&gt;  &lt;p&gt;2, Add a reference to System.Runtime.Serialization&lt;/p&gt;  &lt;p&gt;3, Rename the existing Class1.cs file to Product.cs, and amend/add the following attributes and properties to the class:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:962e18d5-1a50-4292-8854-762b0f2932f3" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;[DataContract]
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; Product
{
    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; ProductId { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }
       
    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; Name { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }
       
    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;decimal&lt;/span&gt;&lt;span style="color: #000000;"&gt; Price { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }
       
    [DataMember]
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; StockLevel { &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;get&lt;/span&gt;&lt;span style="color: #000000;"&gt;; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;set&lt;/span&gt;&lt;span style="color: #000000;"&gt;; }

}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;I’m not going to list the using references you should add at the top of your code. If you get red squiggly lines when compiling, put your cursor on the code in question and do ctrl + . and Visual Studio will assist you in adding the necessary using references.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Creating the Listener project&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;1, Add a new Console application to the Visual Studio Solution called MobileProducts.Listener. &lt;/p&gt;

&lt;p&gt;2, Ensure the project type is .NET Framework 4.0 (rather than .NET 4.0 client profile)&lt;/p&gt;

&lt;p&gt;3, Add a reference to our local project MobileProducts.Model.&lt;/p&gt;

&lt;p&gt;4, Add references to the necessary Azure libraries we will be using. There are:&lt;/p&gt;

&lt;p&gt;System.ServiceModel.dll - this can be found from the standard .NET reference list&lt;/p&gt;

&lt;p&gt;Microsoft.ServiceBus.dll - you'll need to browse to C:\Program Files\Windows Azure SDK\v1.6\ServiceBus\ref\Microsoft.ServiceBus.dll to find it.&lt;/p&gt;

&lt;p&gt;5, Add a Linq 2 SQL class to the project and call it Database.dbml, add the Products table from the simple database you setup and created earlier.&lt;/p&gt;

&lt;p&gt;6, We want to create a method that can be called over the Service Bus that returns a list of products. We'll use a contract/interface so add an interface class to your project called IGetData.cs and ensure it has the following code added:&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:2c61a974-6332-44e5-8346-34c48dd4be8d" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;[ServiceContract(Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Namespace &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;http://MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;)]
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;interface&lt;/span&gt;&lt;span style="color: #000000;"&gt; IGetData
{
    [OperationContract]
    IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MobileProducts.Model.Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetProducts();

    [OperationContract]
    MobileProducts.Model.Product GetProductById(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id);
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;7, Next we can add a class that implements this contract, add a class to the project called GetData.cs and implement the following code...&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:36dcf2b0-1161-40f6-adb8-f5aa77b0ea09" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;[ServiceBehavior(Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Namespace &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;http://MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;)]
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;class&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetData : IGetData
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MobileProducts.Model.Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetProducts()
    {
        DatabaseDataContext db &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; DatabaseDataContext();
        IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MobileProducts.Model.Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; products &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; from p &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; db.Products
                                                             select &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; MobileProducts.Model.Product
                                                             {
                                                                 Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; p.Name,
                                                                 Price &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; p.Price,
                                                                 ProductId &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; p.ProductId,
                                                                 StockLevel &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; p.StockLevel
                                                             };

        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; products;
    }

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; MobileProducts.Model.Product GetProductById(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id)
    {
        DatabaseDataContext db &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; DatabaseDataContext();
        var product &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; db.Products.SingleOrDefault(p &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; p.ProductId &lt;/span&gt;&lt;span style="color: #000000;"&gt;==&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id);

        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; MobileProducts.Model.Product
                            { Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; product.Name,
                              Price &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; product.Price,
                              ProductId &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; product.ProductId,
                              StockLevel &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; product.StockLevel
                            };
    }
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;8, In App.Config we need to describe the bindings we want to use, add the following just beneath the connection strings elements:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6ec9a081-2875-4da0-83eb-9f52250cbdca" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;services&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;service &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="MobileProducts.Listener.GetData"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;endpoint &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;contract&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="MobileProducts.Listener.IGetData"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; binding&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="netTcpRelayBinding"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;service&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;services&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;extensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;add &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="netTcpRelayBinding"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;extensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;9, We can now write the code in Program.cs to connect to our service bus and start listening for calls to execute methods...add this code within the Main method:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:d3145cc2-4e02-415b-bc30-136a86ef6fda" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;Console.Title &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Mobile Products Listener Service&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; nsDmn &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrSecret &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

Uri address &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; ServiceBusEnvironment.CreateServiceUri(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;sb&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, nsDmn, &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProducts&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);

TransportClientEndpointBehavior sharedCreds &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TransportClientEndpointBehavior();
sharedCreds.TokenProvider &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; TokenProvider.CreateSharedSecretTokenProvider(issrName, issrSecret);

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;try&lt;/span&gt;&lt;span style="color: #000000;"&gt;
{
    ServiceHost serviceHost &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ServiceHost(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;typeof&lt;/span&gt;&lt;span style="color: #000000;"&gt;(GetData), address);
    IEndpointBehavior serviceRegSettings &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ServiceRegistrySettings(DiscoveryType.Public);
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;foreach&lt;/span&gt;&lt;span style="color: #000000;"&gt; (ServiceEndpoint serviceEndpoint &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; serviceHost.Description.Endpoints)
    {
        serviceEndpoint.Behaviors.Add(sharedCreds);
    }

    serviceHost.Open();

    Console.WriteLine(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Service Information: &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #000000;"&gt;+&lt;/span&gt;&lt;span style="color: #000000;"&gt; address);
    Console.WriteLine(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Hit [Enter] to exit application...&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
    Console.ReadLine();

}
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;catch&lt;/span&gt;&lt;span style="color: #000000;"&gt; (Exception ex)
{
    Console.WriteLine(ex.ToString());
    Console.ReadLine();
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;10, Set the following variables:&lt;/p&gt;

&lt;p&gt;nsDmn = the name you gave the Service Bus instance you created&lt;/p&gt;

&lt;p&gt;issrName = the owner&lt;/p&gt;

&lt;p&gt;issrSecret = the default key you got once your Service Bus was created &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Create a test Caller project&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;It's always good to take mini steps and test things a we go along. Eventually our caller project will be the ASP.NET MVC web application, but initially lets create another console application that will act as a caller. If we get any issues it will be much easier to debug each time, make sure we have the Service Bus component working, and then move onto the next stage of building a mobile web app.&lt;/p&gt;

&lt;p&gt;1, Add a new console application to your solution called MobileProducts.Caller.&lt;/p&gt;

&lt;p&gt;2, Change the project from .Net 4.0 Client Profile to standard .Net Framework 4.0 again.&lt;/p&gt;

&lt;p&gt;3, Add a reference to our local project dll, MobileProduct.Model and also Microsoft.ServiceBus and System.ServiceModel&lt;/p&gt;

&lt;p&gt;4, We want to define the contract again, so our program understands the method it will be calling over the Service Bus and the data it will be getting back. Add an interface class to the project called IGetData and add the same code as when we created the contract for our Listener class&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:21054825-29f3-44a1-b654-eedc9add4a91" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;[ServiceContract(Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Namespace &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;http://MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;)]
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;interface&lt;/span&gt;&lt;span style="color: #000000;"&gt; IGetData
{
    [OperationContract]
    IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetProducts();

    [OperationContract]
    Product GetProductById(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id);
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;5, Add an application configuration (app.config) file to the project and add the following service model definition:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:31234bce-c2c7-4a16-8a39-c9143d1d8d1e" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;client&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;endpoint &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="RelayEndpoint"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; contract&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="MobileProducts.Caller.IGetData"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; binding&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="netTcpRelayBinding"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;client&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;extensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;add &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="netTcpRelayBinding"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;extensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;6, Add the following code to the Main method of Program.cs&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6a02dc43-b5da-4bc5-af82-96e193d103a8" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;Console.Title &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Mobile Products Test Caller&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; nsDmn &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrSecret &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

Uri serviceUri &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; ServiceBusEnvironment.CreateServiceUri(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;sb&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, nsDmn, &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProducts&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);

TransportClientEndpointBehavior sharedCreds &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TransportClientEndpointBehavior();
sharedCreds.TokenProvider &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; TokenProvider.CreateSharedSecretTokenProvider(issrName, issrSecret);

ChannelFactory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IGetData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; channelFactory &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ChannelFactory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IGetData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;RelayEndpoint&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; EndpointAddress(serviceUri));

channelFactory.Endpoint.Behaviors.Add(sharedCreds);

IGetData channel &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; channelFactory.CreateChannel();

((ICommunicationObject)channel).Open();

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;try&lt;/span&gt;&lt;span style="color: #000000;"&gt;
{
    IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;MobileProducts.Model.Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; products &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; channel.GetProducts();
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;foreach&lt;/span&gt;&lt;span style="color: #000000;"&gt; (var product &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;in&lt;/span&gt;&lt;span style="color: #000000;"&gt; products)
    {
        Console.WriteLine(product.Name);
    }
}
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;catch&lt;/span&gt;&lt;span style="color: #000000;"&gt; (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

((ICommunicationObject)channel).Close();
channelFactory.Close();

Console.WriteLine(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;Press [Enter] to continue...&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);
Console.ReadLine();
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;7, As with the Listener project, set the same values for nsDmn, issrName and issrSecret.&lt;/p&gt;

&lt;p&gt;8, Assuming you have some products created in your database table, you can now try the Service Bus out!&lt;/p&gt;

&lt;p&gt;First right click on the MobileProducts.Listener project and choose Debug -&amp;gt; Start New Instance&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Azure Service Bus Listener Application" border="0" alt="Azure Service Bus Listener Application" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_thumb.png" width="644" height="101" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wait for the Service Information to be displayed in the console window&lt;/p&gt;

&lt;p&gt;9, Now right click on the MobileProducts.Caller project and also choose Debug -&amp;gt; Start New Instance&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Azure Service Bus Caller Application" border="0" alt="Azure Service Bus Caller Application" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_thumb_1.png" width="343" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Caller console window you should see a list of product names from your database table! Woot Woot! This means the Caller program is calling the GetData method over the Service Bus, and the Listener is executing this method and returning the data back across the Bus. Pretty awesome!&lt;/p&gt;

&lt;p&gt;The MobileProducts.Caller application has served its purpose. We can now move forward knowing the service bus is working and look at building a mobile application to surface our data.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Create a mobile web app&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Now that we know our Service Bus is setup and working through using the Listener and Caller projects we built, we can move forward and build a Mobile Web Application. We might as well host this in Windows Azure as well.&lt;/p&gt;

&lt;p&gt;1, Right click on the Solution in Visual Studio and choose to Add -&amp;gt; New Project&lt;/p&gt;

&lt;p&gt;2, From the Cloud section pick the Windows Azure Project and call it MobileProducts.Azure&lt;/p&gt;

&lt;p&gt;3, When presented with the list of Azure Projects to create, move the ASP.NET MVC 3 Web Role over.&lt;/p&gt;

&lt;p&gt;4, Right click on the project when it is in the right hand pane and choose 'Rename'. Give it a new name of MobileProducts.WebApp&lt;/p&gt;

&lt;p&gt;5, In the ASP.NET MVC 3 new project dialog use the Empty project template, ensure Razor is selected as the view engine, and tick the box for using HTML 5 semantic markup&lt;/p&gt;

&lt;p&gt;6, Lets do the backend work first and get our web application able to talk to the Service Bus. Add a reference to our local project MobileProducts.Model. Also add a reference to Microsoft.ServiceBus and System.ServiceModel. You should be able to easily pick these from the Recent tab in the 'Add Reference...' dialogue.&lt;/p&gt;

&lt;p&gt;7, In solution explorer, right click on the Models folder in your MVC web app and add a new interface class called IGetData. Add the same code that we previously have done for this interface class:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:eb078a52-ad1b-42af-b054-d07d2184eac2" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;[ServiceContract(Name &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, Namespace &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;http://MobileProductsContract&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;)]
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;interface&lt;/span&gt;&lt;span style="color: #000000;"&gt; IGetData
{
    [OperationContract]
    IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetProducts();

    [OperationContract]
    Product GetProductById(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id);
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;8, Right click on the Models folder and choose to add a new class. Give the class a name of ProductWorker.cs&lt;/p&gt;

&lt;p&gt;9, In the class add the following static methods:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:3f93217e-0bd6-4da3-92ea-a1f6e96a13a6" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; IEnumerable&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Product&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; GetProducts()
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; nsDmn &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrSecret &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

    Uri serviceUri &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; ServiceBusEnvironment.CreateServiceUri(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;sb&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, nsDmn, &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProducts&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);

    TransportClientEndpointBehavior sharedCreds &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TransportClientEndpointBehavior();
    sharedCreds.TokenProvider &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; TokenProvider.CreateSharedSecretTokenProvider(issrName, issrSecret);

    ChannelFactory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IGetData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; channelFactory &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ChannelFactory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IGetData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;RelayEndpoint&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; EndpointAddress(serviceUri));

    channelFactory.Endpoint.Behaviors.Add(sharedCreds);

    IGetData channel &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; channelFactory.CreateChannel();

    ((ICommunicationObject)channel).Open();

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; channel.GetProducts();
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;static&lt;/span&gt;&lt;span style="color: #000000;"&gt; Product GetProductById(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; nsDmn &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrName &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;string&lt;/span&gt;&lt;span style="color: #000000;"&gt; issrSecret &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #800000;"&gt;""&lt;/span&gt;&lt;span style="color: #000000;"&gt;;

    Uri serviceUri &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; ServiceBusEnvironment.CreateServiceUri(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;sb&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, nsDmn, &lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProducts&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;);

    TransportClientEndpointBehavior sharedCreds &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; TransportClientEndpointBehavior();
    sharedCreds.TokenProvider &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; TokenProvider.CreateSharedSecretTokenProvider(issrName, issrSecret);

    ChannelFactory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IGetData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt; channelFactory &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; ChannelFactory&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;IGetData&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;(&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #800000;"&gt;RelayEndpoint&lt;/span&gt;&lt;span style="color: #800000;"&gt;"&lt;/span&gt;&lt;span style="color: #000000;"&gt;, &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;new&lt;/span&gt;&lt;span style="color: #000000;"&gt; EndpointAddress(serviceUri));

    channelFactory.Endpoint.Behaviors.Add(sharedCreds);

    IGetData channel &lt;/span&gt;&lt;span style="color: #000000;"&gt;=&lt;/span&gt;&lt;span style="color: #000000;"&gt; channelFactory.CreateChannel();

    ((ICommunicationObject)channel).Open();

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; channel.GetProductById(Id);
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;10, In the Views folder, right click and add a new folder called Home. Right click the Home folder and add a View called Index, and then add a View called Product&lt;/p&gt;

&lt;p&gt;11, Right click the Controllers folder and add a new Controller called 'HomeController' created using the 'Empty controller' template&lt;/p&gt;

&lt;p&gt;12, In HomeController.cs amend the code to look like this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:c86dd1bf-d2b5-47d9-96fd-a8251574be51" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; ActionResult Index()
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; View(ProductWorker.GetProducts());
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;public&lt;/span&gt;&lt;span style="color: #000000;"&gt; ActionResult Product(&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;int&lt;/span&gt;&lt;span style="color: #000000;"&gt; Id)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;return&lt;/span&gt;&lt;span style="color: #000000;"&gt; View(ProductWorker.GetProductById(Id));
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;13, Open up web.config and paste in the following XML fragment just after the opening &amp;lt;Configuration&amp;gt;&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:515b1f2d-0b74-4196-8195-11f8d937b895" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;client&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;endpoint &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="RelayEndpoint"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; contract&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="MobileProducts.WebApp.IGetData"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; binding&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="netTcpRelayBinding"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;client&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;extensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;add &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="netTcpRelayBinding"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
      &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;bindingExtensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;extensions&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
  &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;14, Open up Index.cshtml and paste in the following:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:05f57e87-736d-45eb-a0be-9dee6a86f5f6" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;@model IEnumerable&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProducts&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;.Model.Product&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
@{
    ViewBag.Title = "Available Products";
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;h2&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Available Products&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;h2&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

@foreach (var product in Model)
{
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;p&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;@product.Name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;p&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
}
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;15, Hurrah - it's time to test again. Right click your Listener project and Debug - Start new instance, and once that has fired up and is connected to the Service Bus right click your MVC web app and do the same. You should get your list of products displayed.&lt;/p&gt;

&lt;p&gt;Pretty simple, but it shows the data is coming through the Service Bus ok.&lt;/p&gt;

&lt;p&gt;16, We want to make our application really nice to use on mobiles, so lets add in jQueryMobile. In Views -&amp;gt; Shared open _Layout.cshtml. Before the closing &amp;lt;/head&amp;gt; tag add in:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:abd28bf1-3d2c-4a86-b4a6-d1f70b467c00" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;link &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;rel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="stylesheet"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; href&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;script &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="text/javascript"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; src&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;script&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;Also change jQuery so it is using the latest version:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:da6c8580-4bde-49ec-a3f8-775ae62e1f93" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;script &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;type&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="text/javascript"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; src&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="http://code.jquery.com/jquery-1.6.4.min.js"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;script&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;17, Final thing to add in the head section is:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:7ec533eb-e927-4950-89c2-dcbe7945fda6" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;meta &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="viewport"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; content&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="width=device-width, initial-scale=1"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;18, Modify the html in your Index.cshtml file to look like this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:793786f2-d06a-4526-b386-b9c6d8a55dae" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;@model IEnumerable&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;MobileProducts&lt;/span&gt;&lt;span style="color: #FF0000;"&gt;.Model.Product&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
@{
    ViewBag.Title = "Available Products";
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;div &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;data-role&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="page"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;div &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;data-role&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="header"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;h2&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Available Products&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;h2&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;div&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;div &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;data-role&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="content"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;ul &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;data-role&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="listview"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; data-inset&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="true"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; data-filter&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="true"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            @foreach (var product in Model)
            {
                &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;li&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;a &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;href&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="/home/product/@product.ProductId"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; data-transition&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="pop"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;@product.Name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;a&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;li&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
            }
        &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;ul&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

    &lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;div&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;div&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;19, Open up Product.cshtml add get your code looking like:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:f0e30b41-9529-4e31-9b84-aa4eff46aa2f" class="wlWriterEditableSmartContent"&gt;&lt;pre style="background-color:#FFFFFF;overflow: auto;"&gt;&lt;span style="color: #000000;"&gt;@model MobileProducts.Model.Product

@{
    ViewBag.Title = "Product";
}

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;h2&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;@Model.Name&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;h2&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;p&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Price : @Model.Price&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;p&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;p&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Stock Level : @Model.StockLevel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;p&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;

&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;a &lt;/span&gt;&lt;span style="color: #FF0000;"&gt;href&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="#"&lt;/span&gt;&lt;span style="color: #FF0000;"&gt; data-rel&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;="back"&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;Back&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;a&lt;/span&gt;&lt;span style="color: #0000FF;"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000;"&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;

&lt;p&gt;20, Go through the process of starting up your Listener project, and then your Web App. Hopefully the UI will look a lot nicer and more jQueryMobile like:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ASP.NET web app running in a standard browser" border="0" alt="ASP.NET web app running in a standard browser" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_thumb_2.png" width="425" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are going to publish our web app to Azure so we can test it on our own mobiles.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Publish to Azure&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Running locally is all good fun, but for our app to be viewable on mobile devices we want to publish it to Azure. Lets go do that...&lt;/p&gt;

&lt;p&gt;1, Right click on MobileProducts.Azure in the solution explorer and choose 'Package...'&lt;/p&gt;

&lt;p&gt;2, Open up &lt;a href="http://www.azure.com/"&gt;www.azure.com&lt;/a&gt; and log in. Click on 'New Hosted Service in the ribbon&lt;/p&gt;

&lt;p&gt;3, Give your hosted service a name, url, pick a region, deployment name - and then browse to the MobileProducts.Azure.cspkg and ServiceConfiguration.Cloud.cscfg files that Visual Studio created for you as part of the Packaging process.&lt;/p&gt;

&lt;p&gt;4, The finally click OK. You can accept the warning that is displayed upon clicking OK as this is just a test app, but if it was a real production level app you'd want to take a bit more notice of it.&lt;/p&gt;

&lt;p&gt;Once Azure has gone through the process of provisioning your new hosted service and uploading your application get out your smartphone and browse to the url you gave your application in Azure. Hopefully you will see something similar to below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="jQueryMobile app running in Windows Phone 7 browser" border="0" alt="jQueryMobile app running in Windows Phone 7 browser" src="http://lightningtools.com/blog/images/lightningtools_com/blog/Windows-Live-Writer/9cdd75cddf45_DC7B/image_thumb_3.png" width="132" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[Click for a larger image]&lt;/p&gt;

&lt;p&gt;Check out how cool the search and page transitions are. jQueryMobile really is nice!&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Things to think about&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Authentication…We’ll be looking into this in future blog posts. At the moment our web app is open to the public so anybody can hit up our url. In most situation’s with company sensitive data we wouldn’t want this to happen.&lt;/p&gt;

&lt;p&gt;Thanks for reading this far, hopefully this post has been useful and has got you excited about Azure and Mobile web apps. Any thoughts or feedback, please leave a comment or email &lt;a href="mailto:nick@lightningtools.com"&gt;nick@lightningtools.com&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;lt;&lt;a href="http://www.twitter.com/nickswan" target="_blank"&gt;nickswan&lt;/a&gt; /&amp;gt;&lt;/p&gt;&lt;img src="http://lightningtools.com/blog/aggbug/310.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lightning Tools</dc:creator>
            <guid>http://lightningtools.com/blog/archive/2012/01/23/mobile-solutions-for-on-premise-data-with-azure-service-bus.aspx</guid>
            <pubDate>Mon, 23 Jan 2012 08:10:11 GMT</pubDate>
            <wfw:comment>http://lightningtools.com/blog/comments/310.aspx</wfw:comment>
            <comments>http://lightningtools.com/blog/archive/2012/01/23/mobile-solutions-for-on-premise-data-with-azure-service-bus.aspx#feedback</comments>
            <wfw:commentRss>http://lightningtools.com/blog/comments/commentRss/310.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
