PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

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