Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 45 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
45
Dung lượng
3,52 MB
Nội dung
CHAPTER 16 WINDOWS AZURE 417 <ConfigurationSettings> <Setting name="DiagnosticsConnectionString" /> <Setting name="Message"/> </ConfigurationSettings> </WebRole> </ServiceDefinition> 4. We will now define the actual value of this setting, so open ServiceDefinition.cscfg and add a new setting inside the ConfigurationSettings element: <Setting name="Message" value="Hello Azure"/> 5. While we are working with ServiceDefinition.cscfg, find the element that reads <Instances count="1"/> and change it to <Instances count="5"/> 6. Changing the instances count tells Azure to create five instances of our application and simulates scaling our application to use five Azure nodes (you will need to set this back before deployment depending on your pricing structure). This setting can be easily amended online; note how easy it is to quickly scale up your application depending on demand. Microsoft recently announced Azure supports an API that allows you to do this programmatically. Your ServiceDefinition.cscfg should now look like <?xml version="1.0"?> <ServiceConfiguration serviceName="Chapter16.HelloAzure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"> <Role name="Chapter16.WebRole"> <Instances count="5" /> <ConfigurationSettings> <Setting name="DiagnosticsConnectionString" value="UseDevelopmentStorage=true" /> <Setting name="Message" value="Hello Azure"/> </ConfigurationSettings> </Role> </ServiceConfiguration> Open Default.aspx.cs and enter the following code: using Microsoft.WindowsAzure.ServiceRuntime; protected void Page_Load(object sender, EventArgs e) { string GreetingString = "" + RoleEnvironment.GetConfigurationSettingValue("message"); Response.Write(GreetingString + " at " + DateTime.Now.ToString()); } 7. Press F5 to run the application and you should see the greeting value we defined output to the screen with the current time and date. CHAPTER 16 WINDOWS AZURE 418 Logging and Debugging When running your Azure applications locally, you can make full use of standard Visual Studio debugging facilities. However, when applications are deployed to the cloud, debugging and logging support is a bit limited at the time of writing. At the time of writing the logging APIs are in a state of flux (http://blogs.msdn.com/windowsazure/ archive/2009/10/03/upcoming-changes-to-windows-azure-logging.aspx) so expect the final version to have performance monitoring features and integration with Azure storage (see the following). Note that the RoleManager.WriteToLog() method that was present in preview versions has been removed. Testing Azure Applications We have now finished our application's development, so we need to test it. Development would be very slow if we had to deploy to the cloud each time to test it, so Microsoft provides a local version of Azure called the development fabric that simulates how our applications will function in the cloud. Before we can run Azure our application, we will need to create the development storage database (which is just a SQL Server database). This seems to be used for deployment and testing of Azure applications. It can also be quite useful for debugging Azure storage issues (discussed later in the chapter). Creating Development Storage To create development storage, open the Windows Azure SDK command prompt (on the Windows menu under the Windows Azure SDK v1.0 folder) and then enter the following command replacing INSTANCENAME with the name of your SQL Server instance (if you don’t want to use an instance just enter a dot to refer to the machine itself): DSInit /sqlinstance:INSTANCENAME After you press return, the DSInit utility will start creating the development storage database (Figure 16-4): Figure 16-4. Creation of development storage CHAPTER 16 WINDOWS AZURE 419 Now press F5 to run your application and you should see an exciting screen like Figure 16-5: Figure 16-5. Hello Azure application Well done—you have created your first Azure application—but don’t close the web browser window just yet. Take a look at the Windows taskbar (you may have to click Show hidden icons if you are using Windows 7) where there will be a small blue Windows Azure flag showing. Left-clicking on this will show you the current Azure storage and development fabric status (Figure 16-6). Figure 16-6. Azure storage Now right-click on the blue flag and notice how you can shut down the development storage and fabric here as well. This time, however, select the option to show the development fabric UI, and you should see a screen similar to Figure 16-7: CHAPTER 16 WINDOWS AZURE 420 Figure 16-7. Development Fabric UI The window is split into two panes. On the left-hand side is a tree structure that allows you to view details of the service and individual web roles, while over on the right is the logging output from the various Azure instances. Service Details Node Click the Service Details node to show you details of where your service is running. Chapter16.HelloAzure Node Right-click on the Chapter16.HelloAzure node and you will see options for starting, suspending, and restarting the services. You can further configure the project restart configuration by right-clicking and selecting Settings. Chapter16.WebRole Node Right-click the web role node and you will see options for clearing the logs and changing the logging level. Left-clicking the web role node will expand it to show all instances of the application running, which are represented by a number of green globes. The black screens on the left show the output from the individual nodes. CHAPTER 16 WINDOWS AZURE 421 Green Globes If you right-click a green globe (web role) you will see options to attach a debugger and view the local store. Viewing Azure Logs To view the log file of your application, click one of the black screens to see the output. If you right-click on the green globe you have the options to filter the message types displayed by selecting the logging level (Figure 16-8). Figure 16-8. Viewing Azure log on development storage TIP For applications that will be deployed to both standard web servers and Azure it can be useful to determine whether you are running in the fabric. The RoleEnvironment.IsAvailable() method returns a Boolean value indicating this. CHAPTER 16 WINDOWS AZURE 422 Deployment To deploy your application to the cloud you will need a Windows Azure account. If you do not have one yet, what are you waiting for? Go and sign up for one now at http://www.microsoft.com/ windowsazure/account/. Deploying Hello Azure Application Before you deploy your application, check whether you have reset the instance count in the .cscfg file of the Hello Azure application from five to one, as depending on your price plan; otherwise, you may receive an error when you upload your application. OK, let’s deploy the project we created earlier by right-clicking on the HelloAzure project and selecting Publish. Visual Studio will build the application, open the publish directory folder in Windows Explorer and send you to the Windows Azure platform login page. The Windows Azure Portal allows you to deploy, configure and manage your applications. Once you have logged into the services portal and you should see a screen similar to Figure 16-9: Figure 16-9. Azure Services Portal CHAPTER 16 WINDOWS AZURE 423 This page lists all the projects associated with this user. If you haven’t created a project yet, click the adding services to the project link. In the previous example, I have a project called PDC08CTP; click this and you will then be taken to the project services screen (Figure 16-10). Here, if you haven’t already, click the New Service link and add a new hosted service (in the screen shot mine is called Introducing VS2010). Then click on it. Figure 16-10. Project services screen You should then be taken to a screen that shows the current status of your Azure roles (Figure 16-11). CHAPTER 16 WINDOWS AZURE 424 Figure 16-11. Inactive web role Notice at the moment this screen shows only the production instance (see the following section for how to upload to staging instance). We want to upload our application to Windows Azure, so click the Deploy button beneath the staging cube and you will be taken to the Staging Deployment screen. We now need to upload our application itself and its service configuration file. CHAPTER 16 WINDOWS AZURE 425 Application Package Section On the Application Package section, click the Browse button and select the compiled application’s cspkg file (by default this is built at: ~\bin\Debug\Publish\). See Figure 6-12. Figure 16-12. Uploading ServiceConfiguration files Configuration Settings Section On the Configuration Settings section, click the Browse button and select the S Se rviceConfiguration file (default location: ~ ~\He lloAzure\ bin\Debug\ Publish\ServiceConfigu ration.cscfg ). Now give the deployment a descriptive label (e.g., v1.0.0) and click Deploy. Your service will now be deployed to the cloud (Figure 16-13). This is not the quickest process so you may want to go and do something else for five minutes. Once your application has been uploaded, a number of new options will appear beneath the cube enabling you to configure and run it (Figure 16-14). CHAPTER 16 WINDOWS AZURE 426 Figure 16-13. Screen after uploading an application Figure 16-14. Screen after role has been uploaded [...]... version="1 .0" encoding="utf-8"?> b b lobs http://127 .0. 0.1: 100 00/ devstoreaccount1/blobs Mon, 16 Nov 200 9 02 :32:13 GMT 0x8CC 347 C 2 40 E3FE0 p p ictures 43 7 CHAPTER 16 WINDOWS AZURE http://127 .0. 0.1: 100 00/ devstoreaccount1/pictures... 16 Nov 200 9 09 :16 : 40 GMT 0x8CC34B4A41BA4B0 wad-control-container http://127 .0. 0.1: 100 00/ devstoreaccount1/wad-control-container Mon, 16 Nov 200 9 09 :16:21 GMT 0x8CC34B498B195D0 If you want to know more about working with the... variable, 1 40 , 146 BookService class, 269 Booysen, Ray, 44 5 Bounciness property, 399 br snippet, 2 30 breadcrumb trail, 139 bridging protocols, 166 Britcliffe, Andy, 40 7 40 9, 44 6 browser history, for Silverlight 3 .0, 391 browser zoom support, for Silverlight 3 .0, 40 5 BrowserInteropHelper class, 386 brushes, 367–368 C C#, using JSON with, 217 cache dynamic calls, 58 cached composition, 3 84 385 CacheMode... Pricing Servi ce Pricin g Windows Azure Compute @ $0. 12 / hour Storage @ $0. 15 / GB stored Storage Transactions @ $0. 01 / 10K Bandwidth $0. 10 in / $0. 15 out / GB SQL Azure Web Edition – Up to 1 GB relational database @ $9.99 Business Edition – Up to 10 GB relational database @ $99.99 Bandwidth – $0. 10 in / $0. 15 out / GB NET Services Messages @ $0. 15/ 100 K message operations, including Service Bus messages... structure, 293–2 94 purpose of, 2 90 real world applications, 322 returning Views, 302 routing, 301 running application, 300 – 301 security, 316–317 45 0 TempData, 302 testing creating fake film repository, 318 modify Film_ controller, 321 type initialization, 292 V2, 322 ViewData, 302 viewstate, 292 ASP .NET, new common language runtime (CLR), 68 AspNetCache profile attribute, 172 Aspnet.config file, 247 aspx file,... setting, 3 70, 383 AutoBuffered mode, 116 AutoID setting, 239 AutoScroll option, 1 14 autoupdate of Silverlight 3 .0 applications, 391 axd extension, 316 Azure API, 43 1 43 2 Azure Storage, 43 1 43 2, 43 6 43 8 AzureDataServiceContext project, 44 2 AzureRawHttp application, 43 6 B Background collection, 72 Background option, 368 backupLists section, 166 Bag O'Tricks, 378 BAL (Base Activity Library), 131 Baml 200 6Reader... AccountName, pictures container, and the GUID we used for the ID (this URL is made up of IP:PORT/account/container/blobID) (e.g., http:// 127 .0. 0.1: 100 00/ devstoreaccount1/pictures/4d5eee66-162e-4fb1-afcb-197f083 8 40 07 ) Accessing REST API Directly Now that we have worked with the StorageClient, however, I think that it is useful to understand what is happening behind the scenes In our previous example we created... 383 All service, 44 4 Allow Partially Trusted Callers Attribute (APTCA), 76 analytical data, for Windows Azure deployment, 42 8 Animal class, 49 animation jQuery Core library effects, 281 effect overloads, 2 80 281 Glimmer, 282 jQuery tools, 282 Silverlight animation easing, 385 declarative animation, 347 – 348 programmatic, 345 – 346 responding to user events, 346 Animation.xaml file, 346 announcementEndpoint... property, 2 54 basicHttpBinding method, 161 BigInteger class, 78 Binary Large Object (blobs) data, 43 1 binary XML support, Silverlight 3 .0 performance, 40 3 Bind attribute, 312 bind( ) method, 2 80 bindImages( ) method, 43 3 binding attributes in ASP .NET MVC, 311 changes for WPF 4. 0, 381–382 converters, 266 DataView declarative, 257–258 programmatic, 259–2 60 element to element, in Silverlight 3 .0, 396 to... http://silverlightuk.blogspot.com/ We have covered a huge amount of technologies over the last 40 0 or so pages and it is my hope that I have given you a good overview of all the cool stuff that awaits you in VS 201 0 and net4 It is very likely that you now have many more questions than before you started reading–great! Now that you have an overview of what’s new then it is up to you to explore VS 201 0 and net4 further . IP:PORT/account/container/blobID) (e.g., http:// 127 .0. 0.1: 100 00/ devstoreaccount1/pictures/4d5eee66-162e-4fb1-afcb-197f 083 8 40 07). Accessing REST API Directly Now that we have worked with the StorageClient, however,. November training kit (http://www.microsoft.com/downloads/details.aspx?FamilyID =41 3e88f8-5966-4a83-b 309 - 53b7b77edf 78& amp;displaylang=en), which contains a thumbnail image generator example. In. http://127 .0. 0.1: 100 00/ devstoreaccount1/devstoreaccount1?comp=list 2. Set a number of headers in the request. 3. Set the HTTP verb of the request to describe what we are doing (e.g., GET, PUT). 4.