PageRenderTime 4ms CodeModel.GetById 120ms app.highlight 116ms RepoModel.GetById 15ms app.codeStats 0ms

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

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