Document_FAST.pdf - Download from Wow eBook...

This preview shows page 1 out of 345 pages.

Unformatted text preview: Download from Wow! eBook < ; Windows Azure™ Step by Step Windows Azure™ Step by Step Roberto Brunetti Published with the authorization of Microsoft Corporation by: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, California 95472 Copyright © 2011 by Roberto Brunetti All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-4972-9 123456789 M 654321 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at [email protected] Please tell us what you think of this book at . Microsoft and the trademarks listed at Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, O’Reilly Media, Inc., Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Development Editor: Russell Jones Production Editor: Teresa Elsey Editorial Production: Online Training Solutions, Inc. Technical Reviewer: Brian Keller Indexer: Ginny Munroe Cover Design: Twist Creative • Seattle Cover Composition: Karen Montgomery This book is dedicated to Barbara for her support in every important step of my life. —Roberto Contents at a Glance 1 Introduction to Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Introduction to the Windows Azure Platform . . . . . . . . . . . . . . . . 15 3 Creating a Web Role Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4 Windows Azure Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 5 Tables, Queues, and Worker Roles . . . . . . . . . . . . . . . . . . . . . . . . 111 6 Windows Azure Operating System Details . . . . . . . . . . . . . . . . . 137 7 Building an AppFabric Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 8 WCF Data Services and OData . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 9 Using SQL Azure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 10 Accessing Azure Services from Everywhere . . . . . . . . . . . . . . . . 259 11 Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 vii Table of Contents Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii 1 Introduction to Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Approaches to Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Infrastructure as a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Software as a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Platform as a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Cloud Services Defined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Long-Term Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Windows Azure as a PaaS Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Great Opportunity for Small Businesses . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Great Opportunity for Big Businesses . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Windows Azure and Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2 Introduction to the Windows Azure Platform . . . . . . . . . . . . . . . . 15 The Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Service Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Windows Azure Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 The Worker Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 The Virtual Machine Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Windows Azure AppFabric . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 The Service Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 The Access Control Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 SQL Azure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: microsoft.com/learning/booksurvey ix x Table of Contents 3 Creating a Web Role Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Software Development Kits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Windows Azure Tools for Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Web Role Project Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 The Cloud Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Deployment to Windows Azure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Configuration and Upgrading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Service Definition File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Role Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 4 Windows Azure Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Local Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 The Windows Azure Storage Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Windows Azure Management Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Blob APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 5 Tables, Queues, and Worker Roles . . . . . . . . . . . . . . . . . . . . . . . . 111 The Table Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 The Queue Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 6 Windows Azure Operating System Details . . . . . . . . . . . . . . . . . 137 Live ID, Subscriptions, and Billing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Affinity Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Content Delivery Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Table of Contents 7 Building an AppFabric Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Windows Azure AppFabric Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Service Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Direct Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 HTTP for Management URI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 8 WCF Data Services and OData . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 The Astoria Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 WCF Data Services (ADO.NET Data Services) . . . . . . . . . . . . . . . . . . . . . . . . 194 The Building Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 WCF Data Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Query and Relationship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Filtering, Sorting, and Pagination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 WCF Data Service Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 The .NET Framework Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Security Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 9 Using SQL Azure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 SQL Azure Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 SQL Azure Database Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Database Server Creation in the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 SQL Azure Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 SQL Azure Relational Engine Feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 Existing Database Migration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 SQL Azure Migration Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 xi xii Table of Contents 10 Accessing Azure Services from Everywhere . . . . . . . . . . . . . . . . 259 Creating the Storage Account Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 Accessing the Storage Account from PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Using HTTP and REST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 11 Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Characteristics of a Multitier Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 The Data Access Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 The Service Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 Acknowledgments A book is the result of the work of many people, but usually only the author name appears on the cover. First, I want to thank Vanni Boncinelli for his effort in reviewing all the chapters for both technical aspects and linguistic troubles. This is my first English-written book. Without him, the editor would have rejected all the chapters. I also want to thank Russell Jones for his patience in responding quickly and precisely to all of my rookie questions and for supporting me from the beginning of this writing. Many thanks go to Brian Keller: he has reviewed not only the text but every line of code two times, because during the writing process Microsoft released the SDK 1.3, which was significantly different from the previous version around configuration and the Visual Studio IDE add-in. Brian also had to re-review all the portal screenshots, because the Windows Azure user interface was completely redesigned in Silverlight as of January 2011. One of the most important people to thank is Victoria Thulman, who guided me in the process of copyediting all the chapters. Her patience with my mistakes and incorrect assumptions was immeasurable. Gabriele Castellani and Giuseppe Guerrasio wrote the foreword and have supported me since 2008, when Microsoft first announced Windows Azure at PDC 08. Fabio Santini and Mario Fontana have given me the opportunity to work with many Italian Microsoft partners and with a wide range of application scenarios: you can find those experiences reflected in many of this book’s pages. Last, but not least, thanks to Paolo Pialorsi, who introduced me to Russell Jones one year ago. Now, the book is complete: thanks again to all of you. xiii Download from Wow! eBook < ; Foreword When Roberto asked us to write a foreword for this book, he made us happy for several reasons. First, it’s a pleasure introducing you to the work of one of the members of DevLeap, a group of professionals who have always been distinguished by the quality and the clarity of their teaching materials and courses. Second, the topic discussed in this book touches one of the most important issues for the future of our profession: cloud computing, and in particular, the Windows Azure Platform, which is the first application infrastructure specifically conceived and built for the cloud. The evolution of networks and the growing diffuseness of the Internet, after having transformed the way people consume content, are on the verge of changing the way we think about concepts such as computational power and storage capabilities. We are used to thinking of those as related to local physical machines, but the advent of cloud computing is leading toward a revolution in how we access computational and storage resources. Thanks to the Windows Azure Platform, huge data centers easily provide the computational power, storage, services, and applications developers need to develop their own solutions, transforming them into services accessible on demand. Providing technologies and infrastructures that we are already familiar with, within an on-demand infrastructure, helps to reduce management and hardware and software maintenance and licensing costs and to constantly increase available computational power and storage capacity. In this book, Roberto accompanies us through the world of the Windows Azure platform and services, providing us with detailed but still basic explanations about the objectives and features of the major components of this new platform and telling us how we can leverage this platform to host our own services and applications. Ranging from the core of the Windows Azure Platform to its deployment and monitoring services, from SQL Azure to full integration with the development tools, this book guides us in discovering the main aspects of this new technology, from a concrete, development-oriented perspective and with plenty of practical examples, in line with the philosophy that has always inspired any DevLeap activity. Case studies and practical tips regarding the use of the services and the most efficient implementation strategies show the best way to approach the Windows Azure Platform, allowing us to ride this new technological wave, which is expected to significantly improve our chances to leverage computational power, storage, and basic services, from the beginning. xv xvi Foreword Here begins a new and interesting journey toward a new technological frontier. The only thing you need to do to jump aboard and start exploring this application platform under Roberto’s guidance is to press F5! Giuseppe Guerrasio Architect Evangelist Developers & Platform Evangelism Microsoft Italy Gabriele Castellani Developer & ITPro Evangelist Manager Microsoft Italy Introduction Windows Azure is the Microsoft cloud computing platform that lets developers leverage its powerful, scalable, and fault-tolerant infrastructure to build successful applications. Windows Azure Step by Step provides an organized walkthrough of the Windows Azure platform and its related technologies. The text is decidedly introductory; it discusses every released component, discussing theory interspersed with simple but effective procedures you can follow, and offering downloadable code examples you can use to jump-start your learning about the Azure platform and as a basis for your own explorations. The book provides coverage of every Windows Azure platform component that has been released to production by Microsoft as of the time of this writing, as well as some related technologies, such as WCF Data Services, OData, and the ADO.NET Entity Framework. Who Should Read This Book This book’s goal is to aid .NET d...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture