PageRenderTime 91ms CodeModel.GetById 2ms app.highlight 80ms RepoModel.GetById 1ms app.codeStats 0ms

/articles/cloud-services-dotnet-hybrid-app-using-service-bus-relay.md

https://github.com/Auguronomics/azure-content
Markdown | 804 lines | 591 code | 213 blank | 0 comment | 0 complexity | 12b0a3a09d8338a890f80478f6715ff7 MD5 | raw file
  1<properties linkid="dev-net-tutorials-hybrid-solution" urlDisplayName="Hybrid Application" pageTitle="Hybrid On-Premises/ Cloud Application (.NET) - Windows Azure" metaKeywords="Azure Service Bus tutorial,hybrid .NET" description="Learn how to create a .NET On-Premises/Cloud Hybrid Application Using the Windows Azure Service Bus Relay." metaCanonical="" services="service-bus" documentationCenter=".NET" title=".NET On-Premises/Cloud Hybrid Application Using Service Bus Relay" authors=""  solutions="" writer="sethm" manager="dwrede" editor="mattshel"  />
  2
  3
  4
  5
  6
  7
  8# .NET On-Premises/Cloud Hybrid Application Using Service Bus Relay
  9
 10<h2><span class="short-header">INTRODUCTION</span>INTRODUCTION</h2>
 11
 12Developing hybrid cloud applications with Windows Azure is easy using
 13Visual Studio 2012 and the free Windows Azure SDK for .NET. This guide
 14assumes you have no prior experience using Windows Azure. In less than
 1530 minutes, you will have an application that uses multiple Windows
 16Azure resources up and running in the cloud.
 17
 18You will learn:
 19
 20-   How to create or adapt an existing web service for consumption by a
 21    web solution.
 22-   How to use the Windows Azure Service Bus relay to share data between
 23    a Windows Azure application and a web service hosted elsewhere.
 24
 25[WACOM.INCLUDE [create-account-note](../includes/create-account-note.md)]
 26
 27### HOW THE SERVICE BUS RELAY HELPS WITH HYBRID SOLUTIONS
 28
 29Business solutions are typically composed of a combination of custom
 30code written to tackle new and unique business requirements and existing
 31functionality provided by solutions and systems that are already in
 32place.
 33
 34Solution architects are starting to use the cloud for easier handling of
 35scale requirements and lower operational costs. In doing so, they find
 36that existing service assets they'd like to leverage as building blocks
 37for their solutions are inside the corporate firewall and out of easy
 38reach for access by the cloud solution. Many internal services are not
 39built or hosted in a way that they can be easily exposed at the
 40corporate network edge.
 41
 42The *Service Bus relay* is designed for the use-case of taking existing
 43Windows Communication Foundation (WCF) web services and making those
 44services securely accessible to solutions that reside outside the
 45corporate perimeter without requiring intrusive changes to the corporate
 46network infrastructure. Such Service Bus relay services are still hosted
 47inside their existing environment, but they delegate listening for
 48incoming sessions and requests to the cloud-hosted Service Bus. The
 49Service Bus also protects those services from unauthorized access by
 50using Windows Azure Active Directory Access Control.
 51
 52### THE SOLUTION SCENARIO
 53
 54In this tutorial, you will create an ASP.NET MVC 4 web site that will
 55allow you to see a list of products on the product inventory page.
 56
 57![][0]
 58
 59The tutorial assumes that you have product information in an existing
 60on-premises system, and uses the Service Bus relay to reach into that
 61system. This is simulated by a web service that is running in a simple
 62console application and is backed by an in-memory set of products. You
 63will be able to run this console application on your own computer and
 64deploy the web role into Windows Azure. By doing so, you will see how
 65the web role running in the Windows Azure datacenter will indeed call
 66into your computer, even though your computer will almost certainly
 67reside behind at least one firewall and a network address translation
 68(NAT) layer.
 69
 70A screenshot of the start page of the completed web application is
 71below.
 72
 73![][1]
 74
 75<h2><span class="short-header">SET UP THE ENVIRONMENT</span>SET UP THE DEVELOPMENT ENVIRONMENT</h2>
 76
 77Before you can begin developing your Windows Azure application, you need
 78to get the tools and set-up your development environment.
 79
 801.  To install the Windows Azure SDK for .NET, click the button below:
 81
 82    [Get Tools and SDK][]
 83
 842. 	Click **install the SDK**.
 85
 863. 	Choose the link for the version of Visual Studio you are using. The steps in this tutorial use Visual Studio 2012:
 87
 88	![][42]
 89
 904.  When prompted to run or save **WindowsAzureSDKForNet.exe**, click
 91    **Run**:
 92
 93    ![][2]
 94
 955.  In the Web Platform Installer, click **Install** and proceed with the installation:
 96
 97    ![][3]
 98
 996.  Once the installation is complete, you will have everything
100    necessary to start developing. The SDK includes tools that let you
101    easily develop Windows Azure applications in Visual Studio. If you
102    do not have Visual Studio installed, it also installs the free
103    Visual Studio Express 2012 for Web.
104
105<h2><span class="short-header">CREATE A NAMESPACE</span>CREATE A SERVICE NAMESPACE</h2>
106
107To begin using Service Bus features in Windows Azure, you must first
108create a service namespace. A service namespace provides a scoping
109container for addressing Service Bus resources within your application.
110
111To create a service namespace:
112
1131.  Log on to the [Windows Azure Management Portal][].
114
1152.  In the left navigation pane of the Management Portal, click
116    **Service Bus**.
117
1183.  In the lower pane of the Management Portal, click **Create**.   
119    ![][5]
120
1214.  In the **Add a new namespace** dialog, enter a namespace name.
122    The system immediately checks to see if the name is available.   
123    ![][6]
124
1255.  After making sure the namespace name is available, choose the
126    country or region in which your namespace should be hosted (make
127    sure you use the same country/region in which you are deploying your
128    compute resources).
129
130    IMPORTANT: Pick the **same region** that you intend to choose for
131    deploying your application. This will give you the best performance.
132
1336.	Click the check mark. The system now creates your service
134    namespace and enables it. You might have to wait several minutes as
135    the system provisions resources for your account.
136
137	![][38]
138
139The namespace you created will then appear in the Management Portal and
140takes a moment to activate. Wait until the status is **Active** before
141moving on.
142
143<h2><span class="short-header">OBTAIN MANAGEMENT CREDENTIALS</span>OBTAIN THE DEFAULT MANAGEMENT CREDENTIALS FOR THE NAMESPACE</h2>
144
145In order to perform management operations, such as creating a queue, on
146the new namespace, you need to obtain the management credentials for the
147namespace.
148
1491.  In the main window, click the name of your service namespace.   
150
151	![][39]
152  
153
1542.  Click **Connection Information**.   
155
156	![][40]
157
158
1593.  In the **Access connection information** pane, find the **Default Issuer** and **Default Key** entries.   
160    
161
1624.  Make a note of the key, or copy it to the clipboard.
163
164
165<h2><span class="short-header">CREATE AN ON-PREMISES SERVER</span>CREATE AN ON-PREMISES SERVER</h2>
166
167First, you will build a (mock) on-premises product catalog system. It
168will be fairly simple; you can see this as representing an actual
169on-premises product catalog system with a complete service surface that
170we're trying to integrate.
171
172This project will start as a Visual Studio console application. The
173project uses the Service Bus NuGet package to include the service bus
174libraries and configuration settings. The NuGet Visual Studio extension
175makes it easy to install and update libraries and tools in Visual Studio
176and Visual Studio Express 2012 for Web. The Service Bus NuGet package is the easiest
177way to get the Service Bus API and to configure your application with
178all of the Service Bus dependencies. For details about using NuGet and
179the Service Bus package, see [Using the NuGet Service Bus Package][].
180
181### CREATE THE PROJECT
182
1831.  Using administrator privileges, launch either Microsoft Visual
184    Studio 2012 or Microsoft Visual Studio Express 2012 for Web. To
185    launch Visual Studio with administrator privileges, right-click
186    **Microsoft Visual Studio 2012 (or Microsoft Visual Studio Express 2012 for Web)** and then click **Run as administrator**.
1872.  In Visual Studio, on the **File** menu, click **New**, and then
188    click **Project**.
189
190    ![][10]
191
1923.  From **Installed Templates**, under **Visual C#**, click **Console
193    Application**. In the **Name** box, type the name
194    **ProductsServer**:
195
196    ![][11]
197
1984.  Click **OK** to create the **ProductsServer** project.
1995.  In the **Solution Explorer**, right-click **ProductsServer**, then
200    click **Properties**.
2016.  Click the **Application** tab on the left, then ensure that **.NET
202    Framework 4** or **.NET Framework 4.5** appears in the **Target framework:** dropdown. If not, select it from the dropdown and then click **Yes**
203    when prompted to reload the project.
204
205    ![][12]
206
2077.  If you have already installed the NuGet package manager for Visual Studio, skip to the next step. Otherwise, visit [NuGet][] and click [Install NuGet](http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c). Follow the prompts to install the NuGet package manager, then re-start Visual Studio.
208
2097.  In **Solution Explorer**, right-click **References**, then click
210    **Manage NuGet Packages**...
2118.  In the left-hand column of the NuGet dialog, click **Online**.
212
2139. 	In the right-hand column, click the **Search** box, type "**WindowsAzure**" and select the **Windows
214    Azure Service Bus** item. Click **Install** to complete the
215    installation, then close this dialog.
216
217    ![][13]
218
219    Note that the required client assemblies are now referenced.
220
2219.  Add a new class for your product contract. In **Solution Explorer**,
222    right click the **ProductsServer** project and click **Add**, then click
223    **Class**.
224
225    ![][14]
226
22710. In the **Name** box, type the name **ProductsContract.cs**. Then
228    click **Add**.
22911. In **ProductsContract.cs**, replace the namespace definition with
230    the following code, which defines the contract for the service:
231
232        namespace ProductsServer
233        {
234            using System.Collections.Generic;
235            using System.Runtime.Serialization;
236            using System.ServiceModel;
237
238            // Define the data contract for the service
239            [DataContract]
240            // Declare the serializable properties
241            public class ProductData
242            {
243                [DataMember]
244                public string Id { get; set; }
245                [DataMember]
246                public string Name { get; set; }
247                [DataMember]
248                public string Quantity { get; set; }
249            }
250
251            // Define the service contract.
252            [ServiceContract]
253            interface IProducts
254            {
255                [OperationContract]
256                IList<ProductData> GetProducts();
257
258            }
259
260            interface IProductsChannel : IProducts, IClientChannel
261            {
262            }
263        }
264
26512. In Program.cs, replace the namespace definition with the following
266    code, which adds the profile service and the host for it:
267
268        namespace ProductsServer
269        {
270            using System;
271            using System.Linq;
272            using System.Collections.Generic;
273            using System.ServiceModel;
274
275            // Implement the IProducts interface
276            class ProductsService : IProducts
277            {
278                
279                // Populate array of products for display on Web site
280                ProductData[] products = 
281                    new []
282                        {
283                            new ProductData{ Id = "1", Name = "Rock", 
284                                             Quantity = "1"},
285                            new ProductData{ Id = "2", Name = "Paper", 
286                                             Quantity = "3"},
287                            new ProductData{ Id = "3", Name = "Scissors", 
288                                             Quantity = "5"},
289                            new ProductData{ Id = "4", Name = "Well", 
290                                             Quantity = "2500"},
291                        };
292
293                // Display a message in the service console application 
294                // when the list of products is retrieved
295                public IList<ProductData> GetProducts()
296                {
297                    Console.WriteLine("GetProducts called.");
298                    return products;
299                }
300
301            }
302
303            class Program
304            {
305                // Define the Main() function in the service application
306                static void Main(string[] args)
307                {
308                    var sh = new ServiceHost(typeof(ProductsService));
309                    sh.Open();
310
311                    Console.WriteLine("Press ENTER to close");
312                    Console.ReadLine();
313
314                    sh.Close();
315                }
316            }
317        }
318
31913. In **Solution Explorer**, double click the **app.config** file to
320    open it in the **Visual Studio** editor. Replace the contents of
321    **&lt;system.ServiceModel>** with the following XML code. Be sure to
322    replace *yourServiceNamespace* with the name of your service
323    namespace, and *yourIssuerSecret* with the key you retrieved earlier
324    from the Windows Azure Management Portal:
325
326        <system.serviceModel>
327          <extensions>
328             <behaviorExtensions>
329                <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
330              </behaviorExtensions>
331              <bindingExtensions>
332                 <add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
333              </bindingExtensions>
334          </extensions>
335          <services>
336             <service name="ProductsServer.ProductsService">
337               <endpoint address="sb://yourServiceNamespace.servicebus.windows.net/products" binding="netTcpRelayBinding" contract="ProductsServer.IProducts"
338        behaviorConfiguration="products"/>
339             </service>
340          </services>
341          <behaviors>
342             <endpointBehaviors>
343               <behavior name="products">
344                 <transportClientEndpointBehavior>
345                    <tokenProvider>
346                       <sharedSecret issuerName="owner" issuerSecret="yourIssuerSecret" />
347                    </tokenProvider>
348                 </transportClientEndpointBehavior>
349               </behavior>
350             </endpointBehaviors>
351          </behaviors>
352        </system.serviceModel>
353
35414. Press **F6** or from the **Build** menu, click **Build Solution** to build the application to verify the accuracy of your work so far.
355
356<h2><span class="short-header">CREATE AN ASP.NET APPLICATION</span>CREATE AN ASP.NET MVC 4 APPLICATION</h2>
357
358In this section you will build a simple MVC 4 application that will
359display data retrieved from your product service.
360
361### CREATE THE PROJECT
362
3631.  Ensure that Microsoft Visual Studio 2012 is runnning with administrator privileges. If not, to
364    launch Visual Studio with administrator privileges, right-click
365    **Microsoft Visual Studio 2012 (or Microsoft Visual Studio Express 2012 for Web)** and then click Run as administrator. The Windows
366    Azure compute emulator, discussed later in this guide, requires that
367    Visual Studio be launched with administrator privileges.
368
3692.  In Visual Studio, on the **File** menu, click **New**, and then
370    click **Project**.
371
3723.  From **Installed Templates**, under **Visual C#**, click **ASP.NET
373    MVC 4 Web Application**. Name the project **ProductsPortal**. Then
374    click **OK**.
375
376    ![][15]
377
3784.  From the **Select a template** list, click **Internet Application**,
379    then click **OK**.
380
381    ![][16]
382
3835.  In **Solution Explorer**, right click **Models** and click **Add**,
384    then click **Class**. In the **Name** box, type the name
385    **Product.cs**. Then click **Add**.
386
387    ![][17]
388
389### MODIFY THE WEB APPLICATION
390
3911.  In the Product.cs file in Visual Studio, replace the existing
392    namespace definition with the following code:
393
394        // Declare properties for the products inventory
395        namespace ProductsWeb.Models
396        {
397            public class Product
398            {
399                public string Id { get; set; }
400                public string Name { get; set; }
401                public string Quantity { get; set; }
402            }
403        }
404
4052.  In the HomeController.cs file in Visual Studio, replace the existing
406    namespace definition with the following code:
407
408        namespace ProductsWeb.Controllers
409        {
410            using System.Collections.Generic;
411            using System.Web.Mvc;
412            using Models;
413
414            public class HomeController : Controller
415            {
416                // Return a view of the products inventory
417                public ActionResult Index(string Identifier, string ProductName)
418                {
419                    var products = new List<Product> 
420                        {new Product {Id = Identifier, Name = ProductName}};
421                    return View(products);
422                }
423
424            }
425        }
426
4273.  In **Solution Explorer**, expand Views\Shared:
428
429    ![][18]
430
4314.  Next, double-click _Layout.cshtml to open it in the Visual Studio editor.
432
4335.  Within the body tag, find the title of the page enclosed in `title` tags.
434    Change the title text from **My MVC Application** to **LITWARE's Products**. Also change **your logo here** to **LITWARE's Products**.
435
4366. Remove the **Home**, **About**, and **Contact** links. Delete the highlighted code:
437
438	![][41]
439
4407.  In **Solution Explorer**, expand Views\Home:
441
442    ![][20]
443
4448.  Double-click Index.cshtml to open it in the Visual Studio editor.
445    Replace the entire contents of the file with the following code:
446	
447		@model IEnumerable<ProductsWeb.Models.Product>
448
449		@{
450    		ViewBag.Title = "Index";
451		}
452
453		<h2>Prod Inventory</h2>
454
455		<table>
456    		<tr>
457        		<th>
458            		@Html.DisplayNameFor(model => model.Name)
459        		</th>
460                <th></th>
461        		<th>
462            		@Html.DisplayNameFor(model => model.Quantity)
463        		</th>
464    		</tr>
465	
466		@foreach (var item in Model) {
467    		<tr>
468        		<td>
469            		@Html.DisplayFor(modelItem => item.Name)
470        		</td>
471        		<td>
472            		@Html.DisplayFor(modelItem => item.Quantity)
473        		</td>
474    		</tr>	
475		}
476
477		</table>
478
479
4809.  To verify the accuracy of your work so far, you can press **F6** or
481    **Ctrl+Shift+B** to build the project.
482
483
484### RUN YOUR APPLICATION LOCALLY
485
486Run the application to verify that it works.
487
4881.  Ensure that **ProductsPortal** is the active project. Right-click
489    the project name in **Solution Explorer** and select **Set As
490    Startup Project**
4912.  Within **Visual Studio**, press **F5**.
4923.  Your application should appear running in a browser:
493
494    ![][21]
495
496    <h2><span class="short-header">DEPLOY TO WINDOWS AZURE</span>MAKE YOUR APPLICATION READY TO DEPLOY TO WINDOWS AZURE</h2>
497
498    You can deploy your application to a Windows Azure Cloud Service or to a Windows Azure Web Site. To learn more about the difference between web sites and cloud services, see [Windows Azure Execution Models][executionmodels]. To learn how to deploy the application to a Windows Azure Web Site, see [Deploying an ASP.NET Web Application to a Windows Azure Web Site](http://www.windowsazure.com/en-us/develop/net/tutorials/get-started/). This section contains detailed steps for deploying the application to a Windows Azure Cloud Service.
499
500    To deploy your application to a cloud service, you'll add a cloud service project deployment project to the solution.
501    The deployment project contains configuration
502    information that is needed to properly run your application in the
503    cloud.
504
505    1.  To make your application deployable to the cloud, right-click
506        the **ProductsPortal** project in **Solution Explorer** and
507        click **Add Windows Azure Cloud Service Project**.
508
509        ![][22]
510
511    2.  To test your application, press **F5**.
512    3.  This will start the Windows Azure compute emulator. The compute
513        emulator uses the local computer to emulate your application
514        running in Windows Azure. You can confirm the emulator has
515        started by looking at the system tray:
516
517        ![][23]
518
519    4.  A browser will still display your application running locally,
520        and it will look and function the same way it did when you ran
521        it earlier as a regular ASP.NET MVC 4 application.
522
523    <h2><span class="short-header">PUT THE PIECES TOGETHER</span>PUT THE PIECES TOGETHER</h2>
524
525    The next step is to hook up the on-premises products server with the
526    ASP.NET MVC4 application.
527
528    1.  If it is not already open, in Visual Studio re-open the
529        **ProductsPortal** project you created in the "Creating an
530        ASP.NET MVC 4 Application" section.
531
532    2.  Similar to the step in the "Create an On-Premises Server"
533        section, add the NuGet package to the project References. In
534        Solution Explorer, right-click **References**, then click
535        **Manage NuGet Packages**.
536
537    3.  Search for "WindowsAzure.ServiceBus" and select the **Windows
538        Azure Service Bus** item. Then complete the installation and
539        close this dialog.
540
541    4.  In Solution Explorer, right-click the **ProductsPortal**
542        project, then click **Add**, then **Existing Item**.
543
544    5.  Navigate to the **ProductsContract.cs** file from the
545        **ProductsServer** console project. Click to highlight
546        ProductsContract.cs. Click the down arrow next to **Add**, then
547        click **Add as Link**.
548
549        ![][24]
550
551    6.  Now open the **HomeController.cs** file in the Visual Studio
552        editor and replace the namespace definition with the following
553        code. Be sure to replace *yourServiceNamespace* with the name of
554        your service namespace, and *yourIssuerSecret* with your key.
555        This will allow the client to call the on-premises service,
556        returning the result of the call.
557
558            namespace ProductsWeb.Controllers
559            {
560                using System.Linq;
561                using System.ServiceModel;
562                using System.Web.Mvc;
563                using Microsoft.ServiceBus;
564                using Models;
565                using ProductsServer;
566
567                public class HomeController : Controller
568                {
569                    // Declare the channel factory
570                    static ChannelFactory<IProductsChannel> channelFactory;
571
572                    static HomeController()
573                    {
574                        // Create shared secret token credentials for authentication 
575                        channelFactory = new ChannelFactory<IProductsChannel>(new NetTcpRelayBinding(), 
576                            "sb://yourServiceNamespace.servicebus.windows.net/products");
577                        channelFactory.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior { 
578                            TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(
579                                "owner", "yourIssuerSecret") });
580                    }
581
582                    public ActionResult Index()
583                    {
584                        using (IProductsChannel channel = channelFactory.CreateChannel())
585                        {
586                            // Return a view of the products inventory
587                            return this.View(from prod in channel.GetProducts()
588                                             select
589                                                 new Product { Id = prod.Id, Name = prod.Name, 
590                                                     Quantity = prod.Quantity });
591                        }
592                    }
593                }
594            }
595
596    7.  In Solution Explorer, right-click on the **ProductsPortal**
597        solution, click **Add**, then click **Existing Project**.
598
599    8.  Navigate to the **ProductsServer** project, then double-click
600        the **ProductsServer.csproj** solution file to add it.
601
602    9.  In Solution Explorer, right-click the **ProductsPortal**
603        solution and click **Properties**.
604
605    10. On the left-hand side, click **Startup Project**. On the
606        right-hand side, cick **Multiple startup projects**. Ensure that
607        **ProductsServer**, **ProductsPortal.Azure**, and
608        **ProductsPortal** appear, in that order, with **Start** set as
609        the action for **ProductsServer** and **ProductsPortal.Azure**,
610        and **None** set as the action for **ProductsPortal**. For
611        example:
612
613        ![][25]
614
615    11. Still in the Properties dialog, click **ProjectDependencies** on
616        the left-hand side.
617
618    12. In the **Projects** dropdown, click
619        **ProductsServer**. Ensure that **ProductsPortal** is unchecked,
620        and **ProductsPortal.Azure** is checked. Then click **OK**:
621
622        ![][26]
623
624    <h2><span class="short-header">RUN THE APPLICATION</span>RUN THE APPLICATION</h2>
625
626    1.  From the **File** menu in Visual Studio, click **Save All**.
627
628    2.  Press **F5** to build and run the application. The on-premises
629        server (the **ProductsServer** console application) should start
630        first, then the **ProductsWeb** application should start in a
631        browser window, as shown in the screenshot below. This time, you
632        will see that the product inventory lists data retrieved from
633        the product service on-premises system.
634
635        ![][1]
636
637    <h2><span class="short-header">DEPLOY THE APPLICATION</span>DEPLOY YOUR APPLICATION TO WINDOWS AZURE</h2>
638
639    1.  Right-click on the **ProductsPortal** project in **Solution
640        Explorer** and click **Publish to Windows Azure**.
641
642    2.  The first time you publish to Windows Azure, you will first have
643        to download credentials via the link provided in Visual Studio.
644
645        Click **Sign in to download credentials**:
646
647        ![][27]
648
649    3.  Sign-in using your Live ID.
650
651
652    4.  Save the publish profile file to a location on your hard drive
653        where you can retrieve it.
654
655
656    5.  Within the publish dialog, click on **Import**:
657
658        ![][30]
659
660    6.  Browse for and select the file that you just downloaded.
661    7.  Pick the Windows Azure subscription you would like to publish
662        to:
663
664        ![][31]
665
666    8.  Click **Next**. If your subscription doesn't already contain any hosted
667        services, you will be asked to create one. The hosted service
668        acts as a container for your application within your Windows
669        Azure subscription. Enter a name that identifies your
670        application and choose the region for which the application
671        should be optimized. (You can expect faster loading times for
672        users accessing it from this region.)
673
674        ![][32]
675
676    9.  Select the hosted service you would like to publish your
677        application to. Keep the defaults as shown below for the
678        remaining settings. Click **Next**:
679
680        ![][33]
681
682    10. On the last page, click **Publish** to start the deployment
683        process:
684
685        ![][34]
686
687        This will take approximately 5-7 minutes. Since this is the
688        first time you are publishing, Windows Azure provisions a
689        virtual machine (VM), performs security hardening, creates a Web
690        role on the VM to host your application, deploys your code to
691        that Web role, and finally configures the load balancer and
692        networking so your application is available to the public.
693
694    11. While publishing is in progress you will be able to monitor the
695        activity in the **Windows Azure Activity Log** window, which is
696        typically docked to the bottom of Visual Studio or Visual Web
697        Developer:
698
699        ![][35]
700
701    12. When deployment is complete, you can view your Web site by
702        clicking the **Web site URL** link in the monitoring window.
703
704        ![][36]
705
706        Your Web site depends on your on-premises server, so you must
707        run the **ProductsServer** application locally for the Web site
708        to function properly. As you perform requests on the cloud Web
709        site, you will see requests coming into your on-premises console
710        application, as indicated by the "GetProducts called" output
711        displayed in the screenshot below.
712
713        ![][37]
714
715To learn more about the difference between web sites and cloud services, see [Windows Azure Execution Models][executionmodels].
716
717<h2><span class="short-header">DELETE THE APPLICATION</span>STOP AND DELETE YOUR APPLICATION</h2>
718
719After deploying your application, you may want to disable it so you
720can build and deploy other applications within the free 750
721hours/month (31 days/month) of server time.
722
723Windows Azure bills web role instances per hour of server time
724consumed. Server time is consumed once your application is deployed,
725even if the instances are not running and are in the stopped state.
726A free account includes 750 hours/month (31 days/month) of dedicated
727virtual machine server time for hosting these web role instances.
728
729The following steps show you how to stop and delete your
730application.
731
7321.  Login to the [Windows Azure Management Portal],
733        click on Cloud Services, then click the name of your service.
734
7352.  Click the **Dashboard** tab, and then click on **Stop** to temporarily suspend your application. You will
736        be able to start it again just by clicking on Start. Click on
737        Delete to completely remove your application from Windows Azure
738        with no ability to restore it.
739
740	![][43]
741
742<h2><a name="nextsteps"></a><span class="short-header">Next steps</span>Next steps</h2>  
743
744To learn more about Service Bus, see the following resources:  
745  
746* [Windows Azure Service Bus][sbmsdn]  
747* [Service Bus How To's][sbwacom]  
748* [How to Use Service Bus Queues][sbwacomqhowto]  
749
750
751  [0]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hybrid.png
752  [1]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/App2.png
753  [Get Tools and SDK]: http://go.microsoft.com/fwlink/?LinkId=271920
754  [NuGet]: http://nuget.org
755  [2]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-3.png
756  [3]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-4-2-WebPI.png
757  
758  
759  [Windows Azure Management Portal]: http://manage.windowsazure.com
760  [5]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/sb-queues-03.png
761  [6]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/sb-queues-04.png
762  
763  
764  
765  [Using the NuGet Service Bus Package]: http://go.microsoft.com/fwlink/?LinkId=234589
766  [10]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-1.png
767  [11]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-con-1.jpg
768  [12]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-con-3.png
769  [13]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-multi-tier-13.png
770  [14]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-con-4.png
771  [15]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-2.jpg
772  [16]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-4.png
773  [17]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-7.jpg
774  [18]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-10.jpg
775  
776  [20]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-11.png
777  [21]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/App1.png
778  [22]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-21.png
779  [23]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-22.png
780  [24]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-12.png
781  [25]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-13.png
782  [26]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-web-14.png
783  [27]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-33.png
784  
785  
786  [30]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-36.png
787  [31]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-37.png
788  [32]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-38.png
789  [33]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-39.png
790  [34]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-40.png
791  [35]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-41.png
792  [36]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/App2.png
793  [37]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/hy-service1.png
794  [38]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-multi-tier-27.png
795  [39]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/sb-queues-09.png
796  [40]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/sb-queues-06.png
797  [41]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-multi-tier-40.png
798  [42]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-41.png
799  [43]: ./media/cloud-services-dotnet-hybrid-app-using-service-bus-relay/getting-started-hybrid-43.png
800
801  [sbmsdn]: http://msdn.microsoft.com/en-us/library/windowsazure/ee732537.aspx  
802  [sbwacom]: /en-us/manage/services/service-bus/  
803  [sbwacomqhowto]: /en-us/develop/net/how-to-guides/service-bus-queues/
804  [executionmodels]: http://www.windowsazure.com/en-us/develop/net/fundamentals/compute/