PageRenderTime 1210ms CodeModel.GetById 584ms app.highlight 315ms RepoModel.GetById 303ms app.codeStats 0ms

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

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