C fowler azure-dojo


Published on

Migrating an Application to Windows Azure

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

C fowler azure-dojo

  1. 1. Migrating an Application toWindows AzureCloud Dojo
  2. 2. I’m all in.Cory FowlerConsultant, ObjectSharpMicrosoft MVP, Windows Azure@SyntaxC4http://blog.syntaxc4.net gettag.mobi
  3. 3. Starter Site: Nerd Dinner ASP.NET MVC SQL Server Entity Framework IIS
  4. 4. Resulting Site: Nerd Dinner ASP.NET MVC SQL AzureEntity Framework Windows AzureWindows Identity Foundation
  5. 5. A Quick word on Tools
  6. 6. Alright, Let’s do this…
  7. 7. Windows Azure!!!
  8. 8. Windows Azure Compute JIT Knowledge
  9. 9. A Hosted Service is a container for an Application. An Application must consist of at least one Role. A Role is Scalable to meet the demand of traffic.
  10. 10. Role Role Role Web Worker VM ASP.NET Long Running Windows Server WCF Process 2008 R2 Fast CGI Emulates Windows Customized Guest OS Services Emulates IIS
  11. 11. Application Roles Web Site Web Site Back-End Web SiteWeb Site Admin Site Services [Web Role] [Worker Role] [VM Role]
  12. 12. Convert your Web Application To a Web Role
  13. 13. Add Cloud Project1. Right-Click on Solution File.2. Hover over Add Menu Item.3. Click New Project.4. Select your Language of Choice.5. Select Cloud.6. Name your Project and hit OK.
  14. 14. Azurify your Web Application1. Right-Click on Web Project2. Click Manage NuGet Packages3. Filter using Azure Web Role4. Install Windows Azure Web Role Or1. Open Package Manager Console2. TypeInstall-Package WindowsAzure.WebRole-ProjectName NerdDinner PM>
  15. 15. Associate your Web & Cloud Projects 1. Right-Click on Roles Folder in Cloud Project. 2. Click Web Role Project in Solution. 3. Select the Nerd Dinner Project from the Dialog. 4. Click OK.
  16. 16. What did I just do…? JIT Knowledge
  17. 17. Cloud ConfigurationServiceDefinition.csdef[Life-Time]ServiceConfiguration.cscfg[Modifiable]
  18. 18. Service Definition<?xml version="1.0" encoding="utf-8"?><ServiceDefinition name="ExploringServiceDefinition"xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WebRole name="" vmsize="ExtraSmall" enableNativeCodeExecution="true"> <!-- ... --> </WebRole> <WorkerRole name="" vmsize="ExtraSmall"> <!-- ... --> </WorkerRole> <VirtualMachineRole name="" vmsize="ExtraSmall"> <!-- ... --> </VirtualMachineRole></ServiceDefinition>
  19. 19. Service Configuration<ServiceConfiguration serviceName="NerdDinner.Cloud" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*"> <Role name="MvcWebRole1"> <Instances count="1" /> <ConfigurationSettings> <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings> </Role></ServiceConfiguration>
  20. 20. public class WebRole : RoleEntryPoint{ WebRole.cs // Included in Both Web and Worker Role Template public override bool OnStart() { RoleEnvironment.Changing += RoleEnvironmentChanging; return base.OnStart(); } // Included in Worker Role Template - Still available in Web Role but needs to be overridden public override void Run() { base.Run(); } // Not Included but available in Web and Worker Roles public override void OnStop() { base.OnStop(); } // Is not generated ANYWHERE but SHOULD be Implemented private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e) { // If a configuration setting is changing if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)) e.Cancel = true; // Set e.Cancel to true to restart this role instance }}
  21. 21. Prepare your Database For SQL Azure
  22. 22. SQL Azure  Tables, indexes and views  Stored Procedures1GB, 5GB 10-50GB  Triggers  Constraints  Table variables, session temp tables (#t)Web Edition Business Edition  Spatial types, HierarchyId  Data Types Feature Set  XML, Sparse Columns, Filestream  Partitions  Full-text indexes  SQL-CLR
  23. 23. Attach NerdDinner Database1. Open SQL Server Management Studio (SSMS)2. Connect to .SQLExpress3. Right-Click on Databases4. Click Attach…5. Find NerdDinner.mdf in App_Data6. Click OK
  24. 24. Generate Scripts for SQL Azure 1. Right-Click Attached NerdDinner Database 2. Click Tasks 3. Click Generate Scripts… 4. Change Database Engine Type to SQL Azure 5. Click OK 6. Click Finish
  25. 25. Connect to SQL Azurehttps://<servername>.database.windows.net [SSMS]
  26. 26. Create SQL Azure DatabaseNew-SqlAzureServer -SubscriptionId 1. Sign in to Windows Azure Portal -Certificate 2. Open SQL Azure Section -AdministratorLogin 3. Create Server -AdministratorLoginPassword a) Select Region -Location b) Create Administration Credentials c) Add Firewall Rules 4. Create Database a) Enter Database name b) Click OK 5. Copy Connection String from Properties Powershell for Firewall Rules: http://bit.ly/qCvdpN
  27. 27. Run the NerdDinner Scripts1. Open [ File | Script ] NerdDinner.sql2. Execute Script
  28. 28. Cloud Aware Configuration web.config ConnectionStringResolver .Create() .WithCloudConnectionStringName ("NerdDinnerEntities") .WithLocalConnectionStringName ("NerdDinnerEntities") Cloud .ConnectionStringService .cscfg Get it on GitHub: http://bit.ly/r7Hvj0
  29. 29. A Quick Note on Data MigrationToolsDTS Wizard (SSIS)http://bit.ly/gzLsl9BCP Utilityhttp://bit.ly/bQdAInImport/Export[Blog on Import/Export CTP] SQL Azure Data Sync
  30. 30. What About AuthN?SQL Azure Windows Azure Storage Claims Based
  31. 31. SQL Membership ApproachPM> Install-Package System.Web.Providers Remember aspnet_regsql?Download the Updated SQL Azure supported Scripts http://bit.ly/gB5DIt
  32. 32. Windows Azure Storagehttp[s]://account.*.core.windows.net Account Container Item images BLOB Storage NerdDinner Blobs videos locations TABLE Storage NerdDinner Entities dinners rsvp QUEUE[S] Storage NerdDinner Messages resize
  33. 33. ** Experimental ** Windows Azure Storage Membership Approach<membership defaultProvider="TableStorageMembershipProvider"> <providers> <clear /> <add name="TableStorageMembershipProvider“ type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider" description="Membership provider using table storage" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" requiresUniqueEmail="true" passwordFormat="Hashed" allowInsecureRemoteEndpoints="true" /> </providers> </membership> Download ASP.NET Samples: http://bit.ly/pEguoW
  34. 34. Claims Based Authentication Windows Azure Access Control Service ACS (v2.0) enables AuthN with:  Active Directory Federation Service [ADFS]  Facebook  Google  LiveID  Yahoo!  WS-Fed  WS-Trust
  35. 35. How Does Claims Based AuthN Work? JIT Knowledge
  36. 36. Google ID Application 0.2 No Auth 3. Send claimsCustomer Access Control Services 0.3 Redirect to provider
  37. 37. 4. Normalize identity Access Control Services 7. Consume identity Your App Claims Framework 6. Send identityCustomer Application
  38. 38. ACS Friendly AuthN ScreenChanging this… Into this…
  39. 39. Create Access Control Namespace1. Open the Windows Azure Platform Portal2. Select Service bus, Access Control & Caching from the lower left-hand menu3. Click New4. Ensure Access Control is selected 5. Provide a Namespace for your AppFabric Endpoint 6. Click Check Availability 7. Select a Region 8. Click Create Namespace 9. Click on Manage Access Control Service
  40. 40. Add an Identity Provider1. Select Identity Provider (IP) i. Google ii. Yahoo!2. Click Next3. Add path to IP Logo4. Click Save
  41. 41. Create Relying Party Application1. Enter Name2. Enter Realm [localhost is allowed]3. Enter Return URL [localhost is allowed]4. Select SAML 1.15. Select Identity providers i. Google ii. Windows Live6. Select Create new rule group7. Select Use service namespace certificate
  42. 42. Enable Claims-Based AuthN 1. In Visual Studio. Tools > Add STS Reference 2. Ensure the Web.config location is correct 3. Enter the Application UrlRequires Windows Identity Foundation SDK
  43. 43. Enable Claims-Based AuthN 4. Select Use an existing STS 5. Login to Windows Azure Portal 6. Navigate to ACS Menu 7. Select AppFabric endpoint 8. Click manage ACS Service 9. Click on Application integration 10. Select & Copy WS-Federation Metadata Url 11. Switch back to Federation Utility 12. Paste Endpoint in Textbox 13. Next through the remainder of the Tool.
  44. 44. MVC WS-Federation Fix PM> Install-Package SyntaxC4.WindowsAzure.ACSManagement.Mvc<httpRuntime requestValidationType="SyntaxC4.WindowsAzure.ACSManagement.Mvc.WsFederationRequestValidator" />
  45. 45. Include WIF in cspkgCopy Local = True isn’t enough in this caseSpecific Version must be False
  46. 46. Home Realm Discovery Wrapped Up! Home Realm Discovery is the act of retrieving a list of the Identity Providers that are available to your application. PM> Install-Package SyntaxC4.WindowsAzure.ACSManagementpublic ActionResult LogOn(){ var manager = new ACSServiceManager("nerddinnerc4", ""); IIdentityProvider[] providers = manager.GetIdentityProviders<IdentityProvider>(); return View(providers);}
  47. 47. Create a Custom Login Screen<ul class="login"> <% foreach (var ip in Model) { %> <li class="login-item"> <object data="<%: ip.ImageUrl %>" onclick="javascript:location.href=<%: ip.LoginUrl %>"> <a href="<%: ip.LoginUrl %>" class="login-item-link"> <%: ip.Name %></a> </object> </li> <% } %></ul>
  48. 48. To the Cloud!
  49. 49. Publish to Windows Azure1. Right-Click on Cloud Project2. Select Publish…3. Select <Add…> from Credentials Dropdown list a) Give Certificate a Friendly Name b) Copy Certificate Path c) Upload Certificate to Management Portal d) Paste SubscriptionId into dialog 4. Select Deployment Environment 5. Select Storage Account 6. Select Cloud Service Configuration 7. Select Release Build Configuration 8. Click Publish
  50. 50. Dinner Time!
  51. 51. Next Steps…Geo-Distributed Decrease Latency with with Phone App? Windows Azure CDNTraffic Manager
  52. 52. Cloudy Reading
  53. 53. ResourcesBlog http://blog.syntaxc4.netGitHub http://github.com/syntaxc4Windows Azure Platform Training Kit http://bit.ly/jXfyyDWindows Azure Powershell Cmdlets http://bit.ly/m75gEcWindows Azure Tools http://bit.ly/miooC4Cloud Cover Show http://bit.ly/g4nQbTEssential Resources for Windows Azure http://bit.ly/efmzGo