The commoditization of technology has reached its pinnacle with the advent of the recent paradigm of Cloud Computing. Infosys Cloud Computing blog is a platform to exchange thoughts, ideas and opinions with Infosys experts on Cloud Computing

« March 2011 | Main | July 2011 »

June 14, 2011

Basic Azure enabling guide

This blog is basically to onboad any new developer to Azure development environment in the least possible time with the right resources available.

With Azure getting stabilized, there are myriad of Azure related articles and blogs made available in the internet. And sometime it is very much possible for a new comer/ developer to get deviated and get confused from where to start. And eventually instead of understanding the basics of the different azure building blocks, they sometime get lured to creating complex application.

So, this blog is not to teach Azure but provide a beginner with a simple guide with pointers to different resources (articles, blog, SDK samples) which will help him/her to grasp the basics of Azure architecture. And help the developer to move in the right path without wasting his/her precious time in understanding from where to start. I have tried to keep it simple with reference to the basic samples from MSDN, SDK and different blogs but tried to keep the maximum information.

 

Basic Azure enabling guide

(Sources of information - MSDN, Azure portal and blogs)

The purpose of this guide is to collage and provide the different information needed for any new-comer to understand the different development aspects at a single place. This will primarily have seven sections with reference to related samples/ hands-on labs and other information for beginners:

1.       The prerequisites for starting Azure related development

2.       Azure Storage service

3.       Azure Compute Service - web role, worker role and VM role

4.       Windows Azure Platform Management Portal for deploying a role

5.       Azure AppFabric Service bus

6.       SQL Azure

7.       What's New in Windows Azure

The sections will talk about the different important pointers available and the concerned samples from the Azure SDK and other sources so that one may directly refer to those saving his/her precious development time. So, this guide doesn't teach how to code but provides the resources at a single place needed to understand and develop for Azure very easily.

Brief about Windows Azure Platform

 

The Windows Azure Platform is an internet-scale cloud computing services platform hosted in Microsoft data centers. The Windows Azure platform, which provides a range of functionality to build applications that span from consumer web to enterprise scenarios, includes a cloud services operating system and a set of developer services. Windows Azure, SQL Azure, and Windows Azure AppFabric are the key components of the platform.

Windows Azure™ is a cloud services operating system that serves as the development, service hosting and service management environment for the Windows Azure platform. Windows Azure provides developers with on-demand compute and storage to host, scale and manage web applications on the internet through Microsoft® datacenters.

The illustration below shows where Windows Azure fits with the other products and components that are part of the Windows Azure platform.

june_2_1.png

For more information about Windows Azure and the new features available in the latest release, see About Windows Azure.

The prerequisites for starting Azure related development

One may from here in one shot install and configure the development machine to make it Azure enabled with the below tools, settings, etc:

·         Windows Azure Tools for Microsoft Visual Studio

·         Windows Azure SDK

·         Visual Web Developer 2010, if you do not have Visual Studio 2010

·         Required IIS feature settings

·         Required hot fixes

And then by allowing the web installer:

june_2_2.png

Otherwise one may also refer to this for installing or upgrading (from previous versions or releases) the pre-requisites (individually) for making the development machine Azure enabled.

Azure SDK once installed provides the different samples explaining the different capabilities with different level of complexities.

Azure Storage service

(Get the basic hands on lab and sample for beginner from here)

The Windows Azure storage services provide persistent, durable storage in the cloud. To access the storage services, you must have a storage account, which is provided through the Windows Azure Platform Management Portal.

The fundamental storage services include:

·         Blob service, for storing text or binary data

·         Queue service, for reliable, persistent messaging between services

·         Table service, for structured storage that can be queried

The Windows Azure SDK offers a REST API and a managed API for working with the storage services. You may access the storage services from within a service running in Windows Azure or directly over the Internet from any application that can send and receive data over HTTP/HTTPS.

For more information about the REST API for the storage services, see Windows Azure Storage Services REST API Reference. For information about the managed API for the storage services, see Windows Azure Managed Library Reference.

Azure Compute Service - web role, worker role and VM role

(Get the basic hands on lab and sample for beginner from here - web and worker role (Source 1, Source 2 and Source 3) and here -VM role)

Windows Azure offers an internet-scale hosting environment built on geographically distributed data centers. This hosting environment provides a runtime execution environment for managed code.

A Windows Azure compute service is built from one or more roles. A role defines a component that may run in the execution environment; within Windows Azure, a service may run one or more instances of a role.

Windows Azure supports the following three types of roles:

·         A web role is customized for web application programming, as supported by Internet Information Services (IIS) 7 and ASP.NET.

·         A worker role is useful for generalized development, and may perform background processing for a web role.

·         A virtual machine (VM) role provides a user-customized image to make it easier to move existing Windows Server applications to the Windows Azure hosting environment.

A hosted service may be comprised of any combination of role types, and may include multiple roles of each type.

A role may interact with the runtime environment by using the Windows Azure Managed API. See the Windows Azure Managed Library Reference for more information. For more information about designing and developing roles, see Building Windows Azure Applications.

Windows Azure Platform Management Portal for deploying a role

(Get the basic hands on lab and sample for beginner from here (deploying a role in Azure))

The Management Portal is an administrative portal for managing your account and deploying, managing, and monitoring your Windows Azure services. For more information, see The New Management Portal.

Azure AppFabric Service bus

(Get the basic hands on lab and sample for beginner from here)

The Windows Azure AppFabric Service Bus provides a hosted, secure, and widely available infrastructure for widespread communication, large-scale event distribution, naming, and service publishing. AppFabric Service Bus provides connectivity options for Windows Communication Foundation (WCF) and other service endpoints - including REST endpoints -- that would otherwise be difficult or impossible to reach. Endpoints can be located behind network address translation (NAT) boundaries, or bound to frequently-changing, dynamically-assigned IP addresses, or both.

SQL Azure

Microsoft SQL Azure extends SQL Server capabilities to the cloud. SQL Azure provides a relational database service called Microsoft SQL Azure Database, a report generation service called Microsoft SQL Azure Reporting, and a web based database administration and design interface as part of the Windows Azure platform. For more information regarding its capability and new enhancements being added to it, refer to this.

What's New in Windows Azure

For latest updates to the Windows Azure platform and Windows Azure SDK, refer to this.

 

 

June 3, 2011

Basic steps to expose the on-premise WCF service through appfabric Service bus to be used by Silverlight client in the Azure cloud

Basic steps to expose the on-premise WCF service through appfabric Service bus to be used by Silverlight client in the Azure cloud. It also talks about the steps to be followed to move an existing Silverlight client to the Azure. Some of the information has been taken from MSDN, Azure SDK and other blogs. The purpose of this is to provide all the information in a single place and there-by saving the precious time of developer. 

 

Steps to be followed in the service configuration:

1.       To the existing service, add a service end point with binding - "basichttprelaybinding". E.g.-

<service name="<service name>" behaviorConfiguration="WCFonIISServiceBehavior">

<endpoint address="http://<service bus namespace>.servicebus.windows.net/<Service name>/" behaviorConfiguration="sharedSecretClientCredentials" binding="basicHttpRelayBinding" bindingConfiguration="HttpRelayEndpointConfig" name="RelayEndpoint" contract="<service contract>" />

</service>

 

And then add the corresponding binding section-

<bindings>

<basicHttpRelayBinding>

        <binding name="HttpRelayEndpointConfig">

          <security mode="None" relayClientAuthenticationType="None" />

        </binding>

      </basicHttpRelayBinding>

</bindings>

 

2.       Add the end point behavior to configure the credentials needed to connect to appfabric service bus and register the end point URL in the service bus. E.g.- in the end point declaration in step 1, "sharedSecretClientCredentials" is the end point behavior reference.  Add the declaration of the same as:

<endpointBehaviors>

<behavior name="sharedSecretClientCredentials">

<transportClientEndpointBehavior credentialType="SharedSecret">

              <clientCredentials>

<sharedSecret issuerName="<ISSUER NAME>" issuerSecret="<ISSUER KEY>" />

              </clientCredentials>

      </transportClientEndpointBehavior>

       <ServiceRegistrySettings discoveryMode="Public" />

</behavior>

</endpointBehaviors>

 

3.       To understand the steps to be followed to get the service namespace, issuer name and issuer key needed for on-premise service registration, please refer to APPENDIX- C.

4.       To make the end point available in the atom feed exposed by the service bus when the base service bus namespace URL is browsed (e.g.  http://<service-namespace>.servicebus.windows.net/ ); to the end point behavior, one end point setting needs to be added. In step 2 the same has been provided by - "ServiceRegistrySettings"

For using this setting we need to add a class file having the class definition provided in APPENDIX- D with as applicable class namespace name (for the project in concern).

5.       To make "ServiceRegistrySettings" recognizable, we need add the corresponding behavior extensions like:

<extensions>

<behaviorExtensions>

<add name="ServiceRegistrySettings" type="<class namespace>.ServiceRegistrySettingsElement, <class namespace>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

   </behaviorExtensions>

</extensions>

                With as applicable class namespace.

Steps to be followed in the service deployment environment/machine:

The following are the steps to be followed in the machine where the service(s) to be exposed through appfabric service bus will be hosted and running.

1.       To make the service bus related DLLs available, install the "Windows Azure AppFabric SDK" from here.

2.       In the IIS, create the corresponding virtual directory and add the service related files and folders to it.

3.       Install TMG client and enable it with proper TMG forefront/ ISA server settings. Make sure the identity under which the application pool for the service running has internet access.

4.       When any wcf service is hosted in IIS, the service is ignited /started and made to be consumable only when the first request comes. But in this case, service in concern needs to be started before even any request for the service is made. This is because only once the service is started with the above mentioned settings, the service is registered to the service bus and a public URL is exposed which a client in the public (internet) may refer to while making a service request. To achieve this we need to enable the auto-start for the service i.e. the moment the hosting service is started (here IIS), the service hosted also gets started. To enable this, install the "Windows Server AppFabric Setup" from here. Once installed follow APPENDIX- A for the steps for enabling the service auto-start in IIS.

5.       To use the wcf service in a Silverlight client, if the service base url is different from that of the Silverlight client web application; as we know, we need to expose the client access policy xml file at the base address of the service. That is, in case of wcf service exposed through service bus, the client access policy needs to be accessible as - http://<servicebus-namepscae>.servicebus.windows.net/clientaccesspolicy.xml . And since we don't have direct access to keep the said xml file to the root of the service, we need to expose a RESTful wcf service interface through service bus which will serve this purpose of exposing the policy file. For code sample on how to expose client access policy xml file RESTfully, please refer to this.

 

6.       Make sure to expose - http://<servicebus-namepscae>.servicebus.windows.net/clientaccesspolicy.xml only after all the services to be exposed through service bus are started and could be verified by accessing the URL- http://<service-namespace>.servicebus.windows.net/. For the reason of this order of execution, refer to the APPENDIX- B.

Steps to be followed in the Silverlight client application:

1.       In the Silverlight project (i.e. .... SilverlightUX)

a.       If this is a new project then add the service reference to the services

b.      If this is an existing project then either refresh the service reference(s) or in the ServiceReferences.ClientConfig file:

                                                               i.      For the concerned service's client end point add/edit the address attribute to provide the service bus url like- http://<servicebus-namespace>.servicebus.windows.net/<service-name>/  e.g.:

<client>

<endpoint address="http://<service-bus namespace>.servicebus.windows.net/<service name>/"

                binding="basicHttpBinding" bindingConfiguration="RelayEndpoint"

                contract="<service proxy name>.<service contract>" name="RelayEndpoint" />

</client>

 

                                                             ii.      Provide the binding type as "basicHttpBinding" because this is compatible with the "basicHttpRelayBinding" used to register the on-premise service to the service bus. And accordingly provide the binding configuration as needed e.g.:

<bindings>

<basicHttpBinding>

              <binding name="RelayEndpoint" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">

<security mode="None" />

</binding>

       </basicHttpBinding>

</bindings>

 

2.       To the solution having the Silverlight application project and the corresponding hosting website project, add a blank Windows Azure project i.e. without any roles.

a.       Once the Azure project add, on the "Roles" folder right click and add role using the menu-  "Web role project in solution":

1.png

 

b.       And from the shown list select the website project hosting the concerned Silverlight application:

2.png 

3.       If the Silverlight project is of type Business application then for all the WCF RIA services related dlls, make sure to set the property "Copy Local" to true to include these in the deployment package:

 3.png

4.       If the Silverlight application is making use of the "by default provided Login form" then make sure to override at least the method - GetAuthenticatedUser in:

4.png 

If ADFS is used for user authentication then for example override as:

                protected override User GetAuthenticatedUser(System.Security.Principal.IPrincipal principal)

        {

            //return base.GetAuthenticatedUser(principal);

            User claimsUser = new User();

            string alias = "loggedInUser";

            try

            {

                Microsoft.IdentityModel.Claims.IClaimsPrincipal claimsprincipal = principal as Microsoft.IdentityModel.Claims.IClaimsPrincipal;

                Microsoft.IdentityModel.Claims.IClaimsIdentity claimsIdentity = claimsprincipal.Identity as Microsoft.IdentityModel.Claims.IClaimsIdentity;

                foreach (Microsoft.IdentityModel.Claims.Claim claim in claimsIdentity.Claims)

                {

                     if (claim.ClaimType.ToLower().Contains("upn"))

                     {

                         alias = claim.Value.Split('@')[0];

                         break;

                     }

                }

            }

            catch (System.Exception ex)

            {

                alias = ex.Message + ": " + ex.StackTrace;

            }

            claimsUser.FriendlyName = alias;

            claimsUser.Name = alias;

            return claimsUser;

        }

    }

 

This is needed otherwise an error will be thrown by Login form- "Load operation failed for query 'GetUser'.". GetUser internally calls GetAuthenticatedUser. For further understanding and extension please refer to the blog at Enabling Federated Identity in Wcf Ria Services by Robert O'Brien.

APPENDIX- A

1.       Create Virtual Directory for the WCF service-

a.       In the machine (on-premise) where this service is to be deployed, run the visual studio under the administrator privilege. Open the solution and go to the properties of the project having the WCF service declaration.

b.      Go to the "Web" tab:

5.png 

c.       Select "Use Local IIS Web server", with proper project url and click "Create Virtual Directory"

2.       Enable auto-start-

a.       Once the Azure SDK installed, copy the ServiceBus_schema.xml file from <installation folder>\Labs\IntroServiceBus2010Part1\Source\Assets

to %SystemRoot%\System32\inetsrv\config\schema directory. Make sure to keep a copy of the old one (if any) so that if needed could be reverted back to the old file.

b.      Open IIS manager and navigate to the virtual directory created:

6.png

c.       On the right, from the Actions section click "Configure":

7.png

d.       In the "Configure WCF and WF for Application" window, select the "Auto-Start" from left and "Custom" from the right:

8.png

e.       Click Apply and then "Yes" on the subsequent message box.

f.      Click "OK" and then double click on the Services option:

9.png

g.       From the center panel, select the service and then click "Configure":

10.png

h.       In the "Configure Service" window select "Enable" for Auto-Start:

11.png

i.       And once applied, reset IIS:

12.png

APPENDIX- B

Suppose we need to expose the url i.e.  just http://<sevice-namespace>.servicebus.windows.net/ e.g. to expose client access policy file through services bus. Then once the base url (as mentioned earlier) is registered, for any further url registration like http://<sevice-namespace>.servicebus.windows.net/<service-name>/ appfabric will through the below mentioned error message even if the url is tried to register for the first time.

The specified address already exists.Address sb://<namespace>.servicebus.windows.net/<service name>/ already in use.

 So the resolution is, if needed then first register url like http://<sevice-namespace>.servicebus.windows.net/<service-name>/ and then only register the url http://<sevice-namespace>.servicebus.windows.net/ for any appfabric service namespace. 

APPENDIX- C

1.       From the Azure Management Portal, for the concerned subscription, select the "Service Bus, Access Control and Caching":            

13.png            2.       Once project in the AppFabric details page, add a new service namespace:

14.png  

3.       Provide a namespace (e.g. servicesandsupport) and select the region suiting the project:

 

15.png

 

4.       Once the namespace is activated, click on it to get its details on the right:

 

 

16.png 

5.       In the property panel scrol down and click on the "View" button in the Deafult key section:

17.png

 

6.       Make a note of the Service Namespace, Default Issuer Name and Default Issuer Key:

18.png

 

 

APPENDIX- D

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.ServiceModel.Configuration;
using Microsoft.ServiceBus;
using System.Configuration;

namespace <namespace>
{
    public class ServiceRegistrySettingsElement : BehaviorExtensionElement
    {
        private const string displayNameId = "displayName";
        private const string discoveryModeId = "discoveryMode";

        public override Type BehaviorType
        {
            get { return typeof(ServiceRegistrySettings); }
        }

        protected override object CreateBehavior()
        {
            return new ServiceRegistrySettings()
            {
                DiscoveryMode = this.DiscoveryMode,
            };
        }


        [ConfigurationProperty(discoveryModeId, DefaultValue = DiscoveryType.Private)]
        public DiscoveryType DiscoveryMode
        {
            get { return (DiscoveryType)this[discoveryModeId]; }
            set { this[discoveryModeId] = value; }
        }


        public string DisplayName
        {
            get { return (string)this[displayNameId]; }
            set { this[displayNameId] = value; }
        }
    }

}