PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

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