IN ACTION Chris Hay Brian H. Prince M A N N I N G Azure in Action Azure in Action CHRIS HAY BRIAN H. PRINCE MANNING Greenwich (74° w. long.) iv For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact: Special Sales Department Manning Publications Co. 180 Broad Street Suite 1323 Stamford, CT 06901 Email: [email protected] ©2011 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without elemental chlorine. Manning Publications Co. Development editor: Lianna Wlasiuk 180 Broad Street Copyeditor: Joan Celmer Suite 1323 Proofreader: Katie Tennant Stamford, CT 06901 Illustrator: Martin Murtonen Designer: Marija Tudor ISBN: 9781935182481 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 16 15 14 13 12 11 10 brief contents PART 1 WELCOME TO THE CLOUD ............................................ 1 1 ■ Getting to know Windows Azure 3 2 ■ Your first steps with a web role 27 PART 2 UNDERSTANDING THE AZURE SERVICE MODEL............. 49 3 ■ How Windows Azure works 51 4 ■ It’s time to run with the service 78 5 ■ Configuring your service 94 PART 3 RUNNING YOUR SITE WITH WEB ROLES...................... 111 6 ■ Scaling web roles 113 7 ■ Running full-trust, native, and other code 139 PART 4 WORKING WITH BLOB STORAGE ...............................153 8 ■ The basics of BLOBs 155 9 ■ Uploading and downloading BLOBs 181 10 ■ When the BLOB stands alone 209 v vi BRIEF CONTENTS PART 5 WORKING WITH STRUCTURED DATA .......................... 237 11 ■ The Table service, a whole different entity 239 12 ■ Working with the Table service REST API 265 13 ■ SQL Azure and relational data 296 14 ■ Working with different types of data 315 PART 6 DOING WORK WITH MESSAGES................................... 333 15 ■ Processing with worker roles 335 16 ■ Messaging with the queue 357 17 ■ Connecting in the cloud with AppFabric 379 18 ■ Running a healthy service in the cloud 404 contents preface xix acknowledgments xxi about this book xxiv author online xxvi about the authors xxvii about the cover illustration xxix PART 1 WELCOME TO THE CLOUD................................. 1 1 Getting to know Windows Azure 3 1.1 What’s the Windows Azure platform? 4 Windows is in the title, so it must be an operating system 5 Hosting and running applications the Azure way 6 1.2 Building your first Windows Azure web application 9 Setting up your environment 9 ■ Creating a new project 10 Modifying the web page 12 ■ Running the web page 12 1.3 Putting all the Azure pieces together 13 How the load balancer works 13 ■ Creating worker roles 14 How the fabric and the Fabric Controller work 14 vii viii CONTENTS 1.4 Storing data in the cloud with Azure 15 Understanding Azure’s shared storage mechanism 16 ■ Storing and accessing BLOB data 16 ■ Messaging via queues 17 Storing data in tables 18 1.5 Why run in the cloud? 18 Treating computing power as a utility service 19 ■ Simplified data-center management 21 1.6 Inside the Windows Azure platform 23 SQL Server capability in the cloud 23 ■ Enterprise services in the cloud 25 1.7 Summary 26 2 Your first steps with a web role 27 2.1 Getting around the Azure SDK 28 Exploring the SDK folders 29 ■ Using the Cloud Service project templates 29 ■ Running the cloud locally 31 ■ How the local and cloud environments differ 32 2.2 Taking Hello World to the next level 33 Creating the project 33 ■ Laying down some markup with XHTML and a CSS 34 ■ Binding your data in the code- behind 36 ■ Just another place to run your code 37 Configuring the Azure service model 37 ■ Running the website in the local development fabric 38 2.3 Deploying with the Azure portal 39 Signing up for Azure 39 ■ The Azure portal 40 ■ Setting up your service online 41 ■ Putting on your logging boots 43 Setting up your storage environment 43 ■ Packaging and deploying your application 45 ■ Moving to production 47 2.4 Summary 47 PART 2 UNDERSTANDING THE AZURE SERVICE MODEL 49 3 How Windows Azure works 51 3.1 The big shift 51 The data centers of yore 52 ■ The latest Azure data centers 53 How many administrators do you need? 54 ■ Data center: the next generation 55 3.2 Windows Azure, an operating system for the cloud 56 CONTENTS ix 3.3 The Fabric Controller 57 How the FC works: the driver model 58 ■ Resource allocation 58 Instance management 59 3.4 The service model and you 59 Defining configuration 59 ■ Adding a custom configuration element 60 ■ Centralizing file-reading code 61 ■ The many sizes of roles 62 3.5 It’s not my fault 63 Fault domains 63 ■ Update domains 63 ■ A service model example 64 3.6 Rolling out new code 64 Static upgrades 65 ■ Rolling upgrades 66 3.7 The bare metal 68 Free parking 68 ■ A special blend of spices 69 ■ Creating instances on the fly 69 ■ Image is everything 71 3.8 The innards of the web role VM 72 Exploring the VM details 72 ■ The process list 74 ■ The hosting process of your website (WaWebHost) 75 ■ The health of your web role (RDAgent) 76 3.9 Summary 76 4 It’s time to run with the service 78 4.1 Using the Windows Azure Service Management API 78 Adding the ServiceRuntime assembly to your application 79 Is your application running in Windows Azure? 80 4.2 Defining your service 81 The format of the service definition file 81 ■ Configuring the endpoint of your web role 82 ■ Configuring trust level, instances, and startup action 86 ■ Configuring local storage 87 4.3 Setting up certificates in Windows Azure 90 Generating a certificate 90 ■ Adding certificates 91 Configuring your HTTPS endpoint to use the certificate 92 4.4 Summary 93 5 Configuring your service 94 5.1 Working with the service configuration file 94 The format of the service configuration file 95 ■ Configuring standard settings 96 ■ Configuring runtime settings 98
Description: