Azure 云服务定义 WebRole 架构Azure Cloud Services Definition WebRole Schema

Azure Web 角色是针对 IIS 7 所支持的 Web 应用程序编程(例如 ASP.NET、PHP、Windows Communication Foundation 和 FastCGI)自定义的角色。The Azure web role is a role that is customized for web application programming as supported by IIS 7, such as ASP.NET, PHP, Windows Communication Foundation, and FastCGI.

服务定义文件的默认扩展名为 .csdef。The default extension for the service definition file is .csdef.

Web 角色的基本服务定义架构Basic service definition schema for a web role

包含 Web 角色的服务定义文件的基本格式如下。The basic format of a service definition file containing a web role is as follows.

<ServiceDefinition …>  
  <WebRole name="<web-role-name>" vmsize="<web-role-size>" enableNativeCodeExecution="[true|false]">  
    <Certificates>  
      <Certificate name="<certificate-name>" storeLocation="<certificate-store>" storeName="<store-name>" />  
    </Certificates>      
    <ConfigurationSettings>  
      <Setting name="<setting-name>" />  
    </ConfigurationSettings>  
    <Imports>  
      <Import moduleName="<import-module>"/>  
    </Imports>  
    <Endpoints>  
      <InputEndpoint certificate="<certificate-name>" ignoreRoleInstanceStatus="[true|false]" name="<input-endpoint-name>" protocol="[http|https|tcp|udp]" localPort="<port-number>" port="<port-number>" loadBalancerProbe="<load-balancer-probe-name>" />  
      <InternalEndpoint name="<internal-endpoint-name>" protocol="[http|tcp|udp|any]" port="<port-number>">  
         <FixedPort port="<port-number>"/>  
         <FixedPortRange min="<minimum-port-number>" max="<maximum-port-number>"/>  
      </InternalEndpoint>  
     <InstanceInputEndpoint name="<instance-input-endpoint-name>" localPort="<port-number>" protocol="[udp|tcp]">  
         <AllocatePublicPortFrom>  
            <FixedPortRange min="<minimum-port-number>" max="<maximum-port-number>"/>  
         </AllocatePublicPortFrom>  
      </InstanceInputEndpoint>  
    </Endpoints>  
    <LocalResources>  
      <LocalStorage name="<local-store-name>" cleanOnRoleRecycle="[true|false]" sizeInMB="<size-in-megabytes>" />  
    </LocalResources>  
    <LocalStorage name="<local-store-name>" cleanOnRoleRecycle="[true|false]" sizeInMB="<size-in-megabytes>" />  
    <Runtime executionContext="[limited|elevated]">  
      <Environment>  
         <Variable name="<variable-name>" value="<variable-value>">  
            <RoleInstanceValue xpath="<xpath-to-role-environment-settings>"/>  
          </Variable>            
      </Environment>  
      <EntryPoint>  
         <NetFxEntryPoint assemblyName="<name-of-assembly-containing-entrypoint>" targetFrameworkVersion="<.net-framework-version>"/>  
      </EntryPoint>  
    </Runtime>  
    <Sites>  
      <Site name="<web-site-name>">  
        <VirtualApplication name="<application-name>" physicalDirectory="<directory-path>"/>  
        <VirtualDirectory name="<directory-path>" physicalDirectory="<directory-path>"/>  
        <Bindings>  
          <Binding name="<binding-name>" endpointName="<endpoint-name-bound-to>" hostHeader="<url-of-the-site>"/>  
        </Bindings>  
      </Site>  
    </Sites>  
    <Startup priority="<for-internal-use-only>">  
      <Task commandLine="<command-to=execute>" executionContext="[limited|elevated]" taskType="[simple|foreground|background]">  
        <Environment>  
         <Variable name="<variable-name>" value="<variable-value>">  
            <RoleInstanceValue xpath="<xpath-to-role-environment-settings>"/>  
          </Variable>            
        </Environment>  
      </Task>  
    </Startup>  
    <Contents>  
      <Content destination="<destination-folder-name>" >  
        <SourceDirectory path="<local-source-directory>" />  
      </Content>  
    </Contents>  
  </WebRole>  
</ServiceDefinition>  

架构元素Schema elements

服务定义文件包括以下元素,本主题的后续部分将进行详细说明:The service definition file includes these elements, described in detail in subsequent sections in this topic:

WebRoleWebRole

ConfigurationSettingsConfigurationSettings

设置Setting

LocalResourcesLocalResources

LocalStorageLocalStorage

EndpointsEndpoints

InternalEndpointInternalEndpoint

InstanceInputEndpointInstanceInputEndpoint

AllocatePublicPortFromAllocatePublicPortFrom

FixedPortFixedPort

FixedPortRangeFixedPortRange

CertificatesCertificates

证书Certificate

ImportsImports

导入Import

运行时Runtime

环境Environment

变量Variable

RoleInstanceValueRoleInstanceValue

NetFxEntryPointNetFxEntryPoint

站点Sites

站点Site

VirtualApplicationVirtualApplication

VirtualApplicationVirtualApplication

绑定Bindings

BindingBinding

启动Startup

任务Task

ContentsContents

内容Content

SourceDirectorySourceDirectory

WebRoleWebRole

WebRole 元素描述针对 IIS 7 和 ASP.NET 所支持的 Web 应用程序编程自定义的角色。The WebRole element describes a role that is customized for web application programming, as supported by IIS 7 and ASP.NET. 一个服务可以包含零个或多个 Web 角色。A service may contain zero or more web roles.

下表介绍了 WebRole 元素的属性。The following table describes the attributes of the WebRole element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. Web 角色的名称。The name for the web role. 该角色的名称必须唯一。The role's name must be unique.
enableNativeCodeExecutionenableNativeCodeExecution 布尔值boolean 可选。Optional. 默认值是 true默认启用本机代码执行和完全信任。The default value is true; native code execution and full trust are enabled by default. 将此属性设置为 false 可禁用 Web 角色的本机代码执行,并改为使用 Azure 部分信任。Set this attribute to false to disable native code execution for the web role, and use Azure partial trust instead.
vmsizevmsize 字符串string 可选。Optional. 设置此值可更改分配给角色的虚拟机的大小。Set this value to change the size of the virtual machine that is allotted to the role. 默认值是 SmallThe default value is Small. 有关详细信息,请参阅云服务的虚拟机大小For more information, see Virtual Machine sizes for Cloud Services.

ConfigurationSettingsConfigurationSettings

ConfigurationSettings 元素描述 Web 角色的配置设置集合。The ConfigurationSettings element describes the collection of configuration settings for a web role. 此元素是 Setting 元素的父级。This element is the parent of the Setting element.

设置Setting

Setting 元素描述用于为角色实例指定配置设置的名称和值对。The Setting element describes a name and value pair that specifies a configuration setting for an instance of a role.

下表介绍了 Setting 元素的属性。The following table describes the attributes of the Setting element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 配置设置的唯一名称。A unique name for the configuration setting.

角色的配置设置是在服务定义文件中声明并在服务配置文件中设置的名称-值对。The configuration settings for a role are name and value pairs that are declared in the service definition file and set in the service configuration file.

LocalResourcesLocalResources

LocalResources 元素描述 Web 角色的本地存储资源集。The LocalResources element describes the collection of local storage resources for a web role. 此元素是 LocalStorage 元素的父级。This element is the parent of the LocalStorage element.

LocalStorageLocalStorage

LocalStorage 元素标识用于在运行时为服务提供文件系统空间的本地存储资源。The LocalStorage element identifies a local storage resource that provides file system space for the service at runtime. 一个角色可以定义零个或多个本地存储资源。A role may define zero or more local storage resources.

备注

LocalStorage 元素可显示为 WebRole 元素的子级,提供与早期版本的 Azure SDK 的兼容性。The LocalStorage element can appear as a child of the WebRole element to support compatibility with earlier versions of the Azure SDK.

下表介绍了 LocalStorage 元素的属性。The following table describes the attributes of the LocalStorage element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 本地存储的唯一名称。A unique name for the local store.
cleanOnRoleRecyclecleanOnRoleRecycle 布尔值boolean 可选。Optional. 指示重启角色时是否应清理本地存储。Indicates whether the local store should be cleaned when the role is restarted. 默认值为 trueDefault value is true.
sizeInMbsizeInMb intint 可选。Optional. 需要为本地存储分配的存储空间量,以 MB 为单位。The desired amount of storage space to allocate for the local store, in MB. 如果未指定,则分配的默认存储空间为 100 MB。If not specified, the default storage space allocated is 100 MB. 可分配的最小存储空间量为 1 MB。The minimum amount of storage space that may be allocated is 1 MB.

最大的本地资源大小取决于虚拟机大小。The maximum size of the local resources is dependent on the virtual machine size. 有关详细信息,请参阅云服务的虚拟机大小For more information, see Virtual Machine sizes for Cloud Services.

分配给本地存储资源的目录的名称对应于为名称属性提供的值。The name of the directory allocated to the local storage resource corresponds to the value provided for the name attribute.

EndpointsEndpoints

Endpoints 元素描述角色的输入(外部)、内部和实例输入终结点的集合。The Endpoints element describes the collection of input (external), internal, and instance input endpoints for a role. 此元素是 InputEndpointInternalEndpointInstanceInputEndpoint 元素的父级。This element is the parent of the InputEndpoint, InternalEndpoint, and InstanceInputEndpoint elements.

输入和内部终结点是单独分配的。Input and Internal endpoints are allocated separately. 一个服务可共有 25 个输入、内部和实例输入终结点,这些终结点可在一个服务中允许存在的 25 个角色间分配。A service can have a total of 25 input, internal, and instance input endpoints which can be allocated across the 25 roles allowed in a service. 例如,如果有 5 个角色,则可以向每个角色分配 5 个输入终结点,或者向一个角色分配 25 个输入终结点,或者可以向 25 个角色中的每个角色分配 1 个输入终结点。For example, if have 5 roles you can allocate 5 input endpoints per role or you can allocate 25 input endpoints to a single role or you can allocate 1 input endpoint each to 25 roles.

备注

部署的每个角色需要一个实例。Each role deployed requires one instance per role. 订阅的默认预配限制为 20 个内核,因此最多可有 20 个角色实例。The default provisioning for a subscription is limited to 20 cores and thus is limited to 20 instances of a role. 如果应用程序需要的实例数比默认预配提供的数目更多,请参阅计费、订阅管理和配额支持,了解有关提高配额的详细信息。If your application requires more instances than is provided by the default provisioning see Billing, Subscription Management and Quota Support for more information on increasing your quota.

InputEndpointInputEndpoint

InputEndpoint 元素描述 Web 角色的外部终结点。The InputEndpoint element describes an external endpoint to a web role.

可以定义由 HTTP、HTTPS、UDP 和 TCP 终结点组成的多个终结点。You can define multiple endpoints that are a combination of HTTP, HTTPS, UDP, and TCP endpoints. 可以指定为输入终结点选择的任意端口号,但为服务中每个角色指定的端口号必须唯一。You can specify any port number you choose for an input endpoint, but the port numbers specified for each role in the service must be unique. 例如,如果指定 Web 角色要将端口 80 用于 HTTP,将端口 443 用于 HTTPS,则之后可以指定第二个 Web 角色将端口 8080 用于 HTTP,将端口 8043 用于 HTTPS。For example, if you specify that a web role uses port 80 for HTTP and port 443 for HTTPS, you might then specify that a second web role uses port 8080 for HTTP and port 8043 for HTTPS.

下表介绍了 InputEndpoint 元素的属性。The following table describes the attributes of the InputEndpoint element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 外部终结点的唯一名称。A unique name for the external endpoint.
protocolprotocol 字符串string 必需。Required. 外部终结点的传输协议。The transport protocol for the external endpoint. 对于 Web 角色,可能的值为 HTTPHTTPSUDPTCPFor a web role, possible values are HTTP, HTTPS, UDP, or TCP.
portport intint 必需。Required. 外部终结点的端口。The port for the external endpoint. 可以指定所选的任意端口号,但为服务中每个角色指定的端口号必须唯一。You can specify any port number you choose, but the port numbers specified for each role in the service must be unique.

可能的值介于 1 和 65535(包含在内)之间(Azure SDK 1.7 或更高版本)。Possible values range between 1 and 65535, inclusive (Azure SDK version 1.7 or higher).
证书 (certificate)certificate stringstring HTTPS 终结点需要。Required for an HTTPS endpoint. Certificate 元素定义的证书的名称。The name of a certificate defined by a Certificate element.
localPortlocalPort intint 可选。Optional. 指定用于终结点上内部连接的端口。Specifies a port used for internal connections on the endpoint. localPort 属性将终结点上的外部端口映射到角色上的内部端口。The localPort attribute maps the external port on the endpoint to an internal port on a role. 这在以下情况下非常有用:角色必须与端口上的内部组件而非为外部公开的组件进行通信。This is useful in scenarios where a role must communicate to an internal component on a port that different from the one that is exposed externally.

如果未指定,则 localPort 的值与 port 属性相同。If not specified, the value of localPort is the same as the port attribute. localPort 的值设置为“*”会自动分配可使用运行时 API 发现的未分配端口。Set the value of localPort to “*” to automatically assign an unallocated port that is discoverable using the runtime API.

可能的值介于 1 和 65535(包含在内)之间(Azure SDK 1.7 或更高版本)。Possible values range between 1 and 65535, inclusive (Azure SDK version 1.7 or higher).

仅当使用 Azure SDK 1.3 或更高版本时,才提供 localPort 属性。The localPort attribute is only available using the Azure SDK version 1.3 or higher.
ignoreRoleInstanceStatusignoreRoleInstanceStatus 布尔值boolean 可选。Optional. 当此属性的值设置为 true 时,会忽略服务的状态,并且负载均衡器不会删除该终结点。When the value of this attribute is set to true, the status of a service is ignored and the endpoint will not be removed by the load balancer. 此值设置为 true 对调试服务的繁忙实例非常有用。Setting this value to true useful for debugging busy instances of a service. 默认值是 falseThe default value is false. 注意: 即使角色不处于就绪状态,终结点仍可接收流量。Note: An endpoint can still receive traffic even when the role is not in a Ready state.
loadBalancerProbeloadBalancerProbe 字符串string 可选。Optional. 与输入终结点关联的负载均衡器探测的名称。The name of the load balancer probe associated with the input endpoint. 有关详细信息,请参阅 LoadBalancerProbe 架构For more information, see LoadBalancerProbe Schema.

InternalEndpointInternalEndpoint

InternalEndpoint 元素描述 Web 角色的内部终结点。The InternalEndpoint element describes an internal endpoint to a web role. 只向服务中运行的其他角色实例提供内部终结点,而不向服务外部的客户端提供。An internal endpoint is available only to other role instances running within the service; it is not available to clients outside the service. 不包含 Sites 元素的 Web 角色只能有一个 HTTP、UDP 或 TCP 内部终结点。Web roles that do not include the Sites element can only have a single HTTP, UDP, or TCP internal endpoint.

下表介绍了 InternalEndpoint 元素的属性。The following table describes the attributes of the InternalEndpoint element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 内部终结点的唯一名称。A unique name for the internal endpoint.
protocolprotocol 字符串string 必需。Required. 内部终结点的传输协议。The transport protocol for the internal endpoint. 可能的值为 HTTPTCPUDPANYPossible values are HTTP, TCP, UDP, or ANY.

ANY 的值指定允许任何协议、任何端口。A value of ANY specifies that any protocol, any port is allowed.
portport intint 可选。Optional. 用于终结点上内部负载均衡连接的端口。The port used for internal load balanced connections on the endpoint. 负载均衡的终结点使用两个端口。A Load balanced endpoint uses two ports. 用于公共 IP 地址的端口,以及用于专用 IP 地址的端口。The port used for the public IP address, and the port used on the private IP address. 通常这些端口的设置相同,但可以选择使用不同的端口。Typically these are these are set to the same, but you can choose to use different ports.

可能的值介于 1 和 65535(包含在内)之间(Azure SDK 1.7 或更高版本)。Possible values range between 1 and 65535, inclusive (Azure SDK version 1.7 or higher).

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Port 属性。The Port attribute is only available using the Azure SDK version 1.3 or higher.

InstanceInputEndpointInstanceInputEndpoint

InstanceInputEndpoint 元素描述 Web 角色的实例输入终结点。The InstanceInputEndpoint element describes an instance input endpoint to a web role. 实例输入终结点通过使用负载均衡器中的端口转接,关联到特定的角色实例。An instance input endpoint is associated with a specific role instance by using port forwarding in the load balancer. 每个实例输入终结点映射到一系列可能端口中的特定端口。Each instance input endpoint is mapped to a specific port from a range of possible ports. 此元素是 AllocatePublicPortFrom 元素的父级。This element is the parent of the AllocatePublicPortFrom element.

仅当使用 Azure SDK 1.7 或更高版本时,才提供 InstanceInputEndpoint 元素。The InstanceInputEndpoint element is only available using the Azure SDK version 1.7 or higher.

下表介绍了 InstanceInputEndpoint 元素的属性。The following table describes the attributes of the InstanceInputEndpoint element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 终结点的唯一名称。A unique name for the endpoint.
localPortlocalPort intint 必需。Required. 指定需要所有角色实例均对其侦听才能接收负载均衡器转发的传入流量的内部端口。Specifies the internal port that all role instances will listen to in order to receive incoming traffic forwarded from the load balancer. 可能的值介于 1 和 65535(含)之间。Possible values range between 1 and 65535, inclusive.
protocolprotocol 字符串string 必需。Required. 内部终结点的传输协议。The transport protocol for the internal endpoint. 可能的值为 udptcpPossible values are udp or tcp. tcp 用于基于 http/https 的流量。Use tcp for http/https based traffic.

AllocatePublicPortFromAllocatePublicPortFrom

AllocatePublicPortFrom 元素描述可供外部客户用来访问每个实例输入终结点的公共端口范围。The AllocatePublicPortFrom element describes the public port range that can be used by external customers to access each instance input endpoint. 公共 (VIP) 端口号在此范围中分配,并在租户部署和更新过程中分配给每个单独的角色实例终结点。The public (VIP) port number is allocated from this range and assigned to each individual role instance endpoint during tenant deployment and update. 此元素是 FixedPortRange 元素的父级。This element is the parent of the FixedPortRange element.

仅当使用 Azure SDK 1.7 或更高版本时,才提供 AllocatePublicPortFrom 元素。The AllocatePublicPortFrom element is only available using the Azure SDK version 1.7 or higher.

FixedPortFixedPort

FixedPort 元素指定内部终结点的端口,用于在该终结点上实现负载均衡的连接。The FixedPort element specifies the port for the internal endpoint, which enables load balanced connections on the endpoint.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 FixedPort 元素。The FixedPort element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 FixedPort 元素的属性。The following table describes the attributes of the FixedPort element.

AttributeAttribute 类型Type 说明Description
portport intint 必需。Required. 内部终结点的端口。The port for the internal endpoint. 其效果与将 FixedPortRange min 和 max 设置为相同的端口一样。This has the same effect as setting the FixedPortRange min and max to the same port.

可能的值介于 1 和 65535(包含在内)之间(Azure SDK 1.7 或更高版本)。Possible values range between 1 and 65535, inclusive (Azure SDK version 1.7 or higher).

FixedPortRangeFixedPortRange

FixedPortRange 元素指定分配给内部终结点或实例输入终结点的端口的范围,并设置用于在终结点上建立负载均衡连接的端口。The FixedPortRange element specifies the range of ports that are assigned to the internal endpoint or instance input endpoint, and sets the port used for load balanced connections on the endpoint.

备注

FixedPortRange 元素的工作方式取决于它所在的元素。The FixedPortRange element works differently depending on the element in which it resides. FixedPortRange 元素位于 InternalEndpoint 元素中时,它会为运行角色的所有虚拟机打开负载均衡器上 min 和 max 属性范围内的所有端口。When the FixedPortRange element is in the InternalEndpoint element, it opens all ports on the load balancer within the range of the min and max attributes for all virtual machines on which the role runs. FixedPortRange 元素位于 InstanceInputEndpoint 元素中时,它会在运行角色的每个虚拟机上只打开 min 和 max 属性范围内的一个端口。When the FixedPortRange element is in the InstanceInputEndpoint element, it opens only one port within the range of the min and max attributes on each virtual machine running the role.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 FixedPortRange 元素。The FixedPortRange element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 FixedPortRange 元素的属性。The following table describes the attributes of the FixedPortRange element.

AttributeAttribute 类型Type 说明Description
分钟min intint 必需。Required. 范围内的最小端口。The minimum port in the range. 可能的值介于 1 和 65535(包含在内)之间(Azure SDK 1.7 或更高版本)。Possible values range between 1 and 65535, inclusive (Azure SDK version 1.7 or higher).
maxmax 字符串string 必需。Required. 范围内的最大端口。The maximum port in the range. 可能的值介于 1 和 65535(包含在内)之间(Azure SDK 1.7 或更高版本)。Possible values range between 1 and 65535, inclusive (Azure SDK version 1.7 or higher).

证书Certificates

Certificates 元素描述 Web 角色的证书集合。The Certificates element describes the collection of certificates for a web role. 此元素是 Certificate 元素的父级。This element is the parent of the Certificate element. 一个角色可以包含任意数目的关联证书。A role may have any number of associated certificates. 有关使用 certificates 元素的详细信息,请参阅使用证书修改服务定义文件For more information on using the certificates element, see Modify the Service Definition file with a certificate.

CertificateCertificate

Certificate 元素描述与 Web 角色关联的证书。The Certificate element describes a certificate that is associated with a web role.

下表介绍了 Certificate 元素的属性。The following table describes the attributes of the Certificate element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 此证书的名称,用于与 HTTPS InputEndpoint 元素关联时进行引用。A name for this certificate, which is used to refer to it when it is associated with an HTTPS InputEndpoint element.
storeLocationstoreLocation 字符串string 必需。Required. 本地计算机上的证书存储位置,可在其中找到此证书。The location of the certificate store where this certificate may be found on the local machine. 可能值为 CurrentUserLocalMachinePossible values are CurrentUser and LocalMachine.
storeNamestoreName 字符串string 必需。Required. 本地计算机上此证书所在的证书存储的名称。The name of the certificate store where this certificate resides on the local machine. 可能的值包括内置存储名称 MyRootCATrustDisallowedTrustedPeopleTrustedPublisherAuthRootAddressBook,或任何自定义存储名称。Possible values include the built-in store names My, Root, CA, Trust, Disallowed, TrustedPeople, TrustedPublisher, AuthRoot, AddressBook, or any custom store name. 如果指定了自定义存储名称,则会自动创建存储。If a custom store name is specified, the store is automatically created.
permissionLevelpermissionLevel 字符串string 可选。Optional. 指定授予角色进程的访问权限。Specifies the access permissions given to the role processes. 如果只希望提升的进程访问私钥,则指定 elevated 权限。If you want only elevated processes to be able to access the private key, then specify elevated permission. limitedOrElevated 权限允许所有角色进程访问私钥。limitedOrElevated permission allows all role processes to access the private key. 可能的值为 limitedOrElevatedelevatedPossible values are limitedOrElevated or elevated. 默认值是 limitedOrElevatedThe default value is limitedOrElevated.

ImportsImports

Imports 元素描述向来宾操作系统添加组件的 Web 角色的导入模块集合。The Imports element describes a collection of import modules for a web role that add components to the guest operating system. 此元素是 Import 元素的父级。This element is the parent of the Import element. 此元素是可选的,一个角色只能有一个 imports 块。This element is optional and a role can have only one imports block.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Imports 元素。The Imports element is only available using the Azure SDK version 1.3 or higher.

ImportImport

Import 元素指定要添加到来宾操作系统的模块。The Import element specifies a module to add to the guest operating system.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Import 元素。The Import element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 Import 元素的属性。The following table describes the attributes of the Import element.

AttributeAttribute 类型Type 说明Description
moduleNamemoduleName stringstring 必需。Required. 要导入的模块的名称。The name of the module to import. 有效的导入模块为:Valid import modules are:

- RemoteAccess- RemoteAccess
- RemoteForwarder- RemoteForwarder
- Diagnostics- Diagnostics

借助 RemoteAccess 和 RemoteForwarder 模块,可配置远程桌面连接的角色实例。The RemoteAccess and RemoteForwarder modules allow you to configure your role instance for remote desktop connections. 有关详细信息,请参阅启用远程桌面连接For more information see Enable Remote Desktop Connection.

借助 Diagnostics 模块,可收集角色实例的诊断数据。The Diagnostics module allows you to collect diagnostic data for a role instance.

RuntimeRuntime

Runtime 元素描述 Web 角色的环境变量设置集合,这些设置控制 Azure 主机进程的运行时环境。The Runtime element describes a collection of environment variable settings for a web role that control the runtime environment of the Azure host process. 此元素是 Environment 元素的父级。This element is the parent of the Environment element. 此元素是可选的,一个角色只能有一个运行时块。This element is optional and a role can have only one runtime block.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Runtime 元素。The Runtime element is only available using the Azure SDK version 1.3 or higher.

下表描述 Runtime 元素的属性:The following table describes the attributes of the Runtime element:

AttributeAttribute 类型Type 说明Description
executionContextexecutionContext 字符串string 可选。Optional. 指定在其中启动角色进程的上下文。Specifies the context in which the Role Process is launched. 默认上下文为 limitedThe default context is limited.

- limited - 不使用管理员特权启动进程。- limited - The process is launched without Administrator privileges.
- elevated - 使用管理员特权启动进程。- elevated - The process is launched with Administrator privileges.

EnvironmentEnvironment

Environment 元素描述 Web 角色的环境变量设置集合。The Environment element describes a collection of environment variable settings for a web role. 此元素是 Variable 元素的父级。This element is the parent of the Variable element. 一个角色可以包含任意数目的环境变量集。A role may have any number of environment variables set.

VariableVariable

Variable 元素指定要在来宾操作系统中设置的环境变量。The Variable element specifies an environment variable to set in the guest operating.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Variable 元素。The Variable element is only available using the Azure SDK version 1.3 or higher.

下表描述 Variable 元素的属性:The following table describes the attributes of the Variable element:

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 要设置的环境变量的名称。The name of the environment variable to set.
valuevalue 字符串string 可选。Optional. 要为环境变量设置的值。The value to set for the environment variable. 必须包含 value 属性或 RoleInstanceValue 元素。You must include either a value attribute or a RoleInstanceValue element.

RoleInstanceValueRoleInstanceValue

RoleInstanceValue 元素指定要从其中检索变量值的 xPath。The RoleInstanceValue element specifies the xPath from which to retrieve the value of the variable.

下表介绍了 RoleInstanceValue 元素的属性。The following table describes the attributes of the RoleInstanceValue element.

AttributeAttribute 类型Type 说明Description
xpathxpath 字符串string 可选。Optional. 实例的部署设置的位置路径。Location path of deployment settings for the instance. 有关详细信息,请参阅带有 XPath 的配置变量For more information, see Configuration variables with XPath.

必须包含 value 属性或 RoleInstanceValue 元素。You must include either a value attribute or a RoleInstanceValue element.

EntryPointEntryPoint

EntryPoint 元素指定角色的入口点。The EntryPoint element specifies the entry point for a role. 此元素是 NetFxEntryPoint 元素的父级。This element is the parent of the NetFxEntryPoint elements. 借助这些元素,可以指定默认 WaWorkerHost.exe 以外的应用程序充当角色入口点。These elements allow you to specify an application other than the default WaWorkerHost.exe to act as the role entry point.

仅当使用 Azure SDK 1.5 或更高版本时,才提供 EntryPoint 元素。The EntryPoint element is only available using the Azure SDK version 1.5 or higher.

NetFxEntryPointNetFxEntryPoint

NetFxEntryPoint 元素指定要为角色运行的程序。The NetFxEntryPoint element specifies the program to run for a role.

备注

仅当使用 Azure SDK 1.5 或更高版本时,才提供 NetFxEntryPoint 元素。The NetFxEntryPoint element is only available using the Azure SDK version 1.5 or higher.

下表介绍了 NetFxEntryPoint 元素的属性。The following table describes the attributes of the NetFxEntryPoint element.

AttributeAttribute 类型Type 说明Description
assemblyNameassemblyName 字符串string 必需。Required. 包含入口点的程序集的路径和文件名称。The path and file name of the assembly containing the entry point. 该路径相对于文件夹 \%ROLEROOT%\Approot(请勿在 commandLine 中指定 \%ROLEROOT%\Approot,它是假定的) 。The path is relative to the folder \%ROLEROOT%\Approot (do not specify \%ROLEROOT%\Approot in commandLine, it is assumed). %ROLEROOT% 是由 Azure 维护的环境变量,表示角色的根文件夹位置。%ROLEROOT% is an environment variable maintained by Azure and it represents the root folder location for your role. \%ROLEROOT%\Approot 文件夹表示角色的应用程序文件夹。The \%ROLEROOT%\Approot folder represents the application folder for your role.

对于 HWC 角色,路径始终相对于 \%ROLEROOT%\Approot\bin 文件夹。For HWC roles the path is always relative to the \%ROLEROOT%\Approot\bin folder.

对于完整版 IIS 和 IIS Express 的 Web 角色,如果在相对于 \%ROLEROOT%\Approot 文件夹的位置找不到程序集,则会搜索 \%ROLEROOT%\Approot\binFor full IIS and IIS Express web roles, if the assembly cannot be found relative to \%ROLEROOT%\Approot folder, the \%ROLEROOT%\Approot\bin is searched.

完整版 IIS 的这种回退行为并不是建议的最佳做法,在以后的版本中可能被删除。This fall back behavior for full IIS is not a recommend best practice and maybe removed in future versions.
targetFrameworkVersiontargetFrameworkVersion 字符串string 必需。Required. 在其上生成程序集的 .NET Framework 的版本。The version of the .NET framework on which the assembly was built. 例如,targetFrameworkVersion="v4.0"For example, targetFrameworkVersion="v4.0".

SitesSites

Sites 元素描述 Web 角色中托管的网站和 Web 应用程序的集合。The Sites element describes a collection of websites and web applications that are hosted in a web role. 此元素是 Site 元素的父级。This element is the parent of the Site element. 如果不指定 Sites 元素,则会以传统 Web 角色的形式托管 Web 角色,并且 Web 角色中只能托管一个网站。If you do not specify a Sites element, your web role is hosted as legacy web role and you can only have one website hosted in your web role. 此元素是可选的,一个角色只能有一个 sites 块。This element is optional and a role can have only one sites block.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Sites 元素。The Sites element is only available using the Azure SDK version 1.3 or higher.

SiteSite

Site 元素指定属于 Web 角色的一部分的网站或 Web 应用程序。The Site element specifies a website or web application that is part of the web role.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Site 元素。The Site element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 Site 元素的属性。The following table describes the attributes of the Site element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 网站或应用程序的名称。Name of the website or application.
physicalDirectoryphysicalDirectory stringstring 站点根的内容目录的位置。The location of the content directory for the site root. 可将该位置指定为绝对路径或相对于 .csdef 位置。The location can be specified as an absolute path or relative to the .csdef location.

VirtualApplicationVirtualApplication

VirtualApplication 元素定义 Internet Information Services (IIS) 7 中的某个应用程序是通过 HTTP 等协议交付内容或提供服务的文件组。The VirtualApplication element defines an application in Internet Information Services (IIS) 7 is a grouping of files that delivers content or provides services over protocols, such as HTTP. 在 IIS 7 中创建应用程序时,该应用程序的路径将成为站点 URL 的一部分。When you create an application in IIS 7, the application's path becomes part of the site's URL.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 VirtualApplication 元素。The VirtualApplication element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 VirtualApplication 元素的属性。The following table describes the attributes of the VirtualApplication element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 指定用于标识虚拟应用程序的名称。Specifies a name to identify the virtual application.
physicalDirectoryphysicalDirectory 字符串string 必需。Required. 指定包含虚拟应用程序的开发计算机上的路径。Specifies the path on the development machine that contains the virtual application. 在计算模拟器中,IIS 已配置为从此位置检索内容。In the compute emulator, IIS is configured to retrieve content from this location. 部署到 Azure 时,物理目录的内容会连同服务的余下部分一起打包。When deploying to the Azure, the contents of the physical directory are packaged along with the rest of the service. 将服务包部署到 Azure 后,会使用未打包内容的位置配置 IIS。When the service package is deployed to Azure, IIS is configured with the location of the unpacked contents.

VirtualDirectoryVirtualDirectory

VirtualDirectory 元素指定在 IIS 中指定的目录名称(也称为路径),并映射到本地或远程服务器上的物理目录。The VirtualDirectory element specifies a directory name (also referred to as path) that you specify in IIS and map to a physical directory on a local or remote server.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 VirtualDirectory 元素。The VirtualDirectory element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 VirtualDirectory 元素的属性。The following table describes the attributes of the VirtualDirectory element.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 指定用于标识虚拟目录的名称。Specifies a name to identify the virtual directory.
valuevalue physicalDirectoryphysicalDirectory 必需。Required. 指定包含网站或虚拟目录内容的开发计算机上的路径。Specifies the path on the development machine that contains the website or Virtual directory contents. 在计算模拟器中,IIS 已配置为从此位置检索内容。In the compute emulator, IIS is configured to retrieve content from this location. 部署到 Azure 时,物理目录的内容会连同服务的余下部分一起打包。When deploying to the Azure, the contents of the physical directory are packaged along with the rest of the service. 将服务包部署到 Azure 后,会使用未打包内容的位置配置 IIS。When the service package is deployed to Azure, IIS is configured with the location of the unpacked contents.

BindingsBindings

Bindings 元素描述网站的绑定集合。The Bindings element describes a collection of bindings for a website. 它是 Binding 元素的父元素。It is the parent element of the Binding element. 每个 Site 元素都需要此元素。The element is required for every Site element. 有关配置终结点的详细信息,请参阅为角色实例启用通信For more information about configuring endpoints, see Enable Communication for Role Instances.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Bindings 元素。The Bindings element is only available using the Azure SDK version 1.3 or higher.

BindingBinding

Binding 元素指定请求与网站或 Web 应用程序通信时所需的配置信息。The Binding element specifies configuration information required for requests to communicate with a website or web application.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Binding 元素。The Binding element is only available using the Azure SDK version 1.3 or higher.

AttributeAttribute 类型Type 说明Description
namename 字符串string 必需。Required. 指定用于标识绑定的名称。Specifies a name to identify the binding.
endpointNameendpointName 字符串string 必需。Required. 指定要绑定到的终结点名称。Specifies the endpoint name to bind to.
hostHeaderhostHeader 字符串string 可选。Optional. 指定允许在单个 IP 地址/端口号组合中托管多个具有不同主机名的站点的主机名。Specifies a host name that allows you to host multiple sites, with different host names, on a single IP Address/Port number combination.

StartupStartup

Startup 元素描述角色启动时运行的任务的集合。The Startup element describes a collection of tasks that run when the role is started. 此元素可以是 Variable 元素的父级。This element can be the parent of the Variable element. 有关使用角色启动任务的详细信息,请参阅如何配置启动任务For more information about using the role startup tasks, see How to configure startup tasks. 此元素是可选的,一个角色只能有一个启动块。This element is optional and a role can have only one startup block.

下表描述 Startup 元素的属性。The following table describes the attribute of the Startup element.

AttributeAttribute 类型Type 说明Description
prioritypriority intint 仅限内部使用。For internal use only.

TaskTask

Task 元素指定在角色启动时发生的启动任务。The Task element specifies startup task that takes place when the role starts. 启动任务可用于执行准备角色以运行的任务,如安装软件组件或运行其他应用程序。Startup tasks can be used to perform tasks that prepare the role to run such install software components or run other applications. 这些任务会按照它们在 Startup 元素块中出现的顺序执行。Tasks execute in the order in which they appear within the Startup element block.

仅当使用 Azure SDK 1.3 或更高版本时,才提供 Task 元素。The Task element is only available using the Azure SDK version 1.3 or higher.

下表介绍了 Task 元素的属性。The following table describes the attributes of the Task element.

AttributeAttribute 类型Type 说明Description
commandLinecommandLine 字符串string 必需。Required. 包含要运行的命令的脚本(如 CMD 文件)。A script, such as a CMD file, containing the commands to run. 启动命令和批处理文件必须以 ANSI 格式保存。Startup command and batch files must be saved in ANSI format. 在文件开头设置字节顺序标记的文件格式无法得到正确处理。File formats that set a byte-order marker at the start of the file will not process properly.
executionContextexecutionContext stringstring 指定在其中运行脚本的上下文。Specifies the context in which the script is run.

- limited [默认] - 使用与托管进程的角色相同的特权运行。- limited [Default] - Run with the same privileges as the role hosting the process.
- elevated - 使用管理员特权运行。- elevated - Run with administrator privileges.
taskTypetaskType stringstring 指定命令的执行行为。Specifies the execution behavior of the command.

- simple [默认] - 系统等待任务退出,然后再启动其他所有任务。- simple [Default] - System waits for the task to exit before any other tasks are launched.
- background - 系统不会等待任务退出。- background - System does not wait for the task to exit.
- foreground - 与后台相似,但所有前台任务全部退出之前,不会重启角色。- foreground - Similar to background, except role is not restarted until all foreground tasks exit.

内容Contents

Contents 元素描述 Web 角色的内容集合。The Contents element describes the collection of content for a web role. 此元素是 Content 元素的父级。This element is the parent of the Content element.

仅当使用 Azure SDK 1.5 或更高版本时,才提供 Contents 元素。The Contents element is only available using the Azure SDK version 1.5 or higher.

内容Content

Content 元素定义要复制到 Azure 虚拟机的内容的源位置,以及要复制到的目标路径。The Content element defines the source location of content to be copied to the Azure virtual machine and the destination path to which it is copied.

仅当使用 Azure SDK 1.5 或更高版本时,才提供 Content 元素。The Content element is only available using the Azure SDK version 1.5 or higher.

下表介绍了 Content 元素的属性。The following table describes the attributes of the Content element.

AttributeAttribute 类型Type 描述Description
destinationdestination 字符串string 必需。Required. 内容放置在 Azure 虚拟机上的位置。Location on the Azure virtual machine to which the content is placed. 此位置相对于文件夹 %ROLEROOT%\ApprootThis location is relative to the folder %ROLEROOT%\Approot.

此元素是 SourceDirectory 元素的父元素。This element is the parent element of the SourceDirectory element.

SourceDirectorySourceDirectory

SourceDirectory 元素定义要从中复制内容的本地目录。The SourceDirectory element defines the local directory from which content is copied. 使用此元素指定要复制到 Azure 虚拟机的本地内容。Use this element to specify the local contents to copy to the Azure virtual machine.

仅当使用 Azure SDK 1.5 或更高版本时,才提供 SourceDirectory 元素。The SourceDirectory element is only available using the Azure SDK version 1.5 or higher.

下表介绍了 SourceDirectory 元素的属性。The following table describes the attributes of the SourceDirectory element.

AttributeAttribute 类型Type 描述Description
pathpath stringstring 必需。Required. 内容将复制到 Azure 虚拟机的本地目录的相对或绝对路径。Relative or absolute path of a local directory whose contents will be copied to the Azure virtual machine. 支持扩展目录路径中的环境变量。Expansion of environment variables in the directory path is supported.

另请参阅See Also

云服务(经典)定义架构Cloud Service (classic) Definition Schema