Web role in Windows azure

Source: Internet
Author: User
Tags remote desktop access azure sdk

Address: http://blog.csdn.net/yuanchunze/article/details/7242437

Web role is mainly used to process HTTP or HTTPS requests. Obviously, this is the most important role. Currently, the Web role instance in Windows azure runs in a virtual machine that contains IIS. Web role can be used to build web applications and Web services. Developers can use. NET technologies such as ASP. NET and WCF, or use non-. NET technologies supported by the FastCGI function module of IIS to create Web role services. Although other roles such as worker role can listen to HTTP and HTTPS requests through settings, Web role is supported by default and is specially designed to process these Web requests. If a service contains multiple web role, different HTTP and HTTPS ports are required.

Understand web role

From the perspective of Role Positioning, Web role is mainly used to build web applications and WCF-based Web Services. Compared with worker role, Web role provides more support for IIS. Windows azure maintains and configures the service running environment, including IIS. Developers only need to build an application according to the Web role programming requirements, and Windows azure can complete all the automatic deployment and configuration of the application.

What is the structure of the web role project? For developers familiar with traditional IIS-based Web application programming, building Web role services is a relatively simple task, because the main components of Web role service implementation are very similar to those of traditional Web applications. If you use the Web role template of Visual Studio to create a project, the project automatically contains three references related to Windows azure.

1. Microsoft. windowsazure. Diagnostics mainly contains diagnostic and log-related classes;

2. Microsoft. windowsazure and serviceruntime mainly include programming interface classes related to role instance lifecycle control and configuration information access;

3. Microsoft. windowsazure. storageclient mainly includes accessing windows azure storage through rest, including blob, table, and queue.

Developers can naturally create a new Web role application using the Web role template provided by Visual Studio. However, if you already have a traditional web application, can it be converted into a web role application? The answer is yes. From the perspective of the project structure, this conversion operation is relatively simple, but if you need to apply some features of Windows Azure, you need to adjust it according to its programming interface. The Windows azure role has some special requirements in terms of status saving and data storage.

In fact, Windows azure projects mainly contain service model information and association information between projects. The specific service logic is implemented by various role projects. From the perspective of Project dependencies, the Windows azure project depends on the role projects it contains.

Understand the Web role running environment

Most developers start to program windows azure from Web role, so further understanding of Web role details helps to understand windows azure's computing service. Next, let's take a look at the specific running environment of the Web role instance, including the underlying virtual machines and IIS services.

When Windows azure was just launched, the running environment of Web role was like a black box. The details of the internal running environment are not disclosed. Web role only supports hosting at that timeCodeAnd can only run in partial trust mode. Developers do not have a simple way to understand the specific running environment of the Web role instance. However, Microsoft later released some new features of Windows Azure, such as full code trust settings and Remote Desktop in management mode, which can help developers understand different role instances (including web role).

Currently, Windows azure roles can be set to run in full trust mode. For example, for Web role, developers only need to set the following in the corresponding service definition file.

[HTML] View plaincopyprint?
    1. <Webrole Name="Webrole1"Endablenativecodeexecution \ "true">

In full trust mode, several code access scenarios are called possibilities.

1. Call non-. Net code. In addition to hosting Code, many developers have already written a lot of local code, especially when dealing with some special tasks. The full trust setting allows the service role to call local code by creating a new process or calling the service through the platform.

2. Use some. Net libraries that require full trust. In the past, Windows azure was unable to call the. NET libraries that require full trust. This restriction is not available now.

3. perform inter-process communication through the named pipe. If the service creates different processes, you can now use the naming pipeline to communicate with them.

In fact, to allow the role to create a local process is Windows azure
An important prerequisite for supporting different language environments. We will find that you need to set full-trust access permissions When configuring PHP support. In addition, you must note that although you have full trust permissions, the role Server
In Windows azure
It does not run as an administrator, so there are some restrictions on the modification of some resources, such as the registry. This is a necessary restriction from the security perspective.

So how do I know some information about the running environment of the Web role instance? We know that in common Windows
In the environment, you can execute commands to understand the system environment. The full trust mode allows developers
The role is generated using the system. Diagnostics. Process class with a cmd.exe
Process, and then pass the command to be executed as a parameter to it and return the command execution result to the client. In addition, developers can use the system. environnment class and
Microsoft. win32.registry class to obtain specific information about the environment.

The Remote Desktop provided by Windows azure gives developers a more intuitive way to understand the role environment. To configure remote desktop access for service roles in Visual Studio, you only need to configure Remote Desktop Connection when publishing applications.

Then, in the configuration window, set the corresponding users and passwords for the Remote Desktop. In this process, Visual Studio
A certificate is generated automatically and the corresponding service definition file and service configuration file are modified automatically. Developers can use Windows azure
The Management Portal uploads the certificate generated in the preceding steps to the certificate directory of the peer service.

The service definition file mainly refers to the <imports> element, which describes the import module to be added to the role runtime environment. This is in Windows
A new feature added after azure SDK 1.3. The <imports> Settings related to Remote Desktop Connection in Web role are mainly
The remoteacess and remoteforwarder modules are as follows.

  1. <Imports>
  2. <ImportmodulenameImportmodulename="Diagnostics"/>
  3. <ImportmodulenameImportmodulename="RemoteAccess"/>
  4. <ImportmodulenameImportmodulename="Remoteforwarder"/>
  5. </Imports>

Remoteacess indicates that the current role supports remote desktop access, while remoteforwarder indicates that the current web role supports RDP access forwarding, because different roles in the user service cannot directly open the RDP access port.

The specific configuration information of remote desktop access, such as user logon information and certificate position, is automatically defined in the service configuration file. As shown below.

  1. <Configurationsettings>
  2. <Setting Name="Microsoft. windowsazure. piugins. Diagnostics. connectionstring" Value="Usedevelopmentstorage = true"/>
  3. <Setting Name="Microsoft. windowsazure. piugins. RemoteAccess. enabled" Value="True"/>
  4. <Setting Name="Microsoft. windowsazure. piugins. RemoteAccess. accountusername" Value="Loginname"/>
  5. ......


after the Remote Desktop Connection is configured, developers can directly connect to the corresponding role instance through RDP on the Windows
azure Management Portal. Developers can have administrator permissions, so that they can learn more about the running environment of the role instance on the familiar Windows server
management interface. For example, you can view the Web role directory structure in the resource manager.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.