收入啤酒88 发表于 2017-7-1 09:33:10

WindowsAzure上把WebApp和WebService同时部署在一个WebRole中

注:本文为个人学习转载,原文地址:http://blog.csdn.net/zztfj/article/details/6740327

  最近开发一个和WindowsAzure相关的应用,该应用还调用了一个WCFService,在开发过程中一直把Web和WCFService分别作为WebRole进行部署,但是,临近末了客户才要求为了节省Azure的相关费用要把二者合并部署。
  如果是普通的Web应用,则可以在IIS中创建一个网站后,把WebService作为其一个虚拟目录即可。经过调查发现这是Windows Azure v1.3 的一个新特性:Full IIS,它允许开发人员在同一个WebRole中创建多个不同的应用。下面这个URL有这方面的更多介绍,请参考http://www.wadewegner.com/2011/02/running-multiple-websites-in-a-windows-azure-web-role/。
  1. 首先,我们先用VS2010创建一个WindowsAzure的解决方案,并添加两个WebRole(WebApp和WebService)。

  2、在解决方案中移除WebService这个项目,同时把FullIIS下的Roles目录中的WebService也删除了。如下图。

  3、通过添加现有项目,把WebService项目再添加到该解决方案中。如下图。

  说明:以上这一删一加的动作,是为了使FullIIS中只有一个WebRole(咱们这篇文章的目的不就是在一个WebRole中既要部署WebApp又要部署WebService这两个应用嘛)。
  4、实现WebService和WebApp的业务逻辑(省略)。
  5、修改ServiceDefinition.csdef文件,在Site下面添加一个VirtualApplication。请参考下面的csdef文件配置。



view plain copy

[*]<?xml version="1.0" encoding="utf-8"?>
[*]<ServiceDefinition name="FullIIS" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
[*]<WebRole name="WebApp">
[*]    <Sites>
[*]      <Site name="Web">
[*]      <VirtualApplication name="Services" physicalDirectory="../WebService" /> <!--重点部分-->
[*]      <Bindings>
[*]          <Binding name="Endpoint1" endpointName="Endpoint1" />
[*]      </Bindings>
[*]      </Site>
[*]    </Sites>
[*]    <Endpoints>
[*]      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
[*]    </Endpoints>
[*]    <Imports>
[*]      <Import moduleName="Diagnostics" />
[*]    </Imports>
[*]</WebRole>
[*]</ServiceDefinition>
  6、在VS2010中,直接F5启动,WebApp已经启动。这时打开“管理工具”——“IIS管理器”,在IIS管理器中可以看到FullIIS.WebApp这个Site下有一个Services的虚拟目录,如下图(日文系统的图片)。

  把该Azure应用打包会生成一个FullIIS.cspkg的发行文件包,把该文件上传到WindowsAzure后就达到了在一个WebRole中通过虚拟目录的方式部署多个应用的目的了。
  注意:在WindowsAzure中最好选择Windows Azure Guest OS 2.0的操作系统,它搭载的是 Windows Server 2008 R2 和IIS 7.5。
页: [1]
查看完整版本: WindowsAzure上把WebApp和WebService同时部署在一个WebRole中