Window Azure(二):开发和发布一个Azure程序

来源:互联网 发布:好用的安卓模拟器知乎 编辑:程序博客网 时间:2024/05/21 08:50
前两天初识 Windows Azure 。
今天主要了解开发和发布一个Azure程序的过程。
准备:
下载开发工具 (Windows Azure Tools for Visual Studio )http://www.microsoft.com/windowsazure/getstarted/
将涉及到的内容:
  • A Windows Azure web role.
  • The Windows Azure compute emulator.(模拟器)
  • A Windows Azure service package.(Azure 服务包)
  • The Windows Azure management portal, http://windows.azure.com.
  • 具体步骤

    安装好Windows Azure Tools后,以管理员身份打开VS2010(win7或Vista用户),创建项目。Create a Windows Azure ASP.NET application

    1. Click OK to close the New Project dialog.

    2. Within the New Windows Azure Project dialog, navigate to Visual C#, click the ASP.NET Web Role, and then click the > symbol. Your New Windows Azure Project dialog should look similar to the following.

      Adding a Web role to the Windows Azure project.

      (添加 a web role 到解决方案. A web role 为网站或应用程序提供被IIS7支持的环境。)

    注意:

    The files are ServiceDefinition.csdef and ServiceConfiguration.cscfg.

    .csdef 后缀文件(ServiceDefinition.csdef )是云服务定义文件( cloud service definition files);

    .cscfg后缀文件是云服务配置文件(ServiceConfiguration.cscfg.)。

    3. 随便修改了一个页面Default.aspx,保存。

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebRole1._Default" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
    Hello,This is my First Windows Azure Code!!
    </h2>
    </asp:Content>
    4. 最后 Ctrl+F5。结果如下:
    调度程序:
    1. 与传统程序无异,不多说。
    查看云计算模拟器械(Windows Azure Emulator)
    点击右下角图标:右键->Show Compute Emulator
    当你运行程序的时候,就可以查看相关信息了。
    具体信息,深入时再谈。
    关于项目类型:Web Role、Work Role 、WCF Service on Web Role 可查点击

    部署服务

    在MSDN上Copy过来,照着做就可以了
    1. 步骤一:在Visual Studio 2010中发布项目

      Solution Explorer窗口中,右击FirstWebRole项目,点击Publish选项:

       

       

      在弹出来的Windows Azure项目部署窗口里,选择Create Service Package Only选项:

       

       

       

      等待Visual Studio 2010创建压缩包完成后,我们将看到一个自动弹出的窗口指向压缩包和配置文件的路径:

       

       

       

      步骤二:进入Windows Azure管理站点

       

      使用支持SilverLight的浏览器打开https://windows.azure.com/(注意:您可能需要输入您的Live ID和密码来通过身份验证)

      步骤三:创建新的Hosted Service

      由于是第一次部署,我们需要先创建一个Hosted Service。点击New Hosted Service按钮:

       

       

      Create a new Hosted Service对话框里,在标记为Choose a subscription 的下拉框里选择一个订阅选项:

       

       

      在标记为Enter a name for your service的文本框里输入服务名称,在标记为Enter a URL prefix for your service的文本框里输入一个URL前缀来指定它的URL

       

       

       

      选择区域:

       

       

       

      选择Do Not Deploy。最后点击OK按钮完成创建:

       

       

       

      步骤四:上传并部署程序压缩包

       

      选中刚刚新建的Hosted Service,然后点击New Staging Deployment按钮:

       

       

       

      在打开的Create a new Deployment对话框里,通过点击两个Browse Locally按钮来选择刚刚生成的程序压缩包FirstWebRole.cspkg和配置文件ServiceConfiguration.cscfg。在标记为Deployment name的文本框里输入一个标签来标记当前这次部署:

       

       

      点击OK开始部署。一个警告对话框将会弹出来提示是否覆盖并提交,想了解详细信息,请点击See more details按钮:

       

       

       

      点击Yes开始覆盖并提交部署请求。

       

       

       

      步骤五:在Staging环境下启动并测试程序

       

      等待一段时间直到部署完成,这个过程将会耗费十几或几十分钟时间。部署完成后,我们就已经上传了程序压缩包并且它已经处于Ready的状态了。请注意管理工具给这个部署分配了一个DNS名称和一个唯一的标识。等下我们就可以通过这个URL去访问并测试这个Web Role程序了。

       

       

      使用浏览器访问该部署的 URL来查看Web Role程序:

       

       

       

      步骤六:将程序转移到Production环境

      确认程序在Staging环境下成功运行之后,选中该部署,点击Swap VIP按钮:

       

       

      Swap VIPs对话框里,点击OK按钮开始将部署从Staging环境转换到Production环境:

       

       

      至此我们已经成功地把我们第一个Web Role程序发布到云端了!现在http://firstservice1.cloudapp.net/可以被任何能够访问Internet的机器访问了。

       

       

       

       

       

      只要部署上到云上,就会开始计费,所以不用的程序一定要删掉!!
    原创粉丝点击