PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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

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