Windows azure Series II: worker Role & Web role

Source: Internet
Author: User

Next, we will focus on worker role and web role.

1. What is role?

Role can be understood as a deployment method. What we want to runProgramIn the final sense, it is necessary to run on the process. Our development programs are divided into Windows Service, web application, Silverlight, and so on, each of which has its own unique advantages and differences. However, the underlying layers are all host-based processes, and each process is relatively closed, in order to pass data between processes, I/O, remoting, and the most common WCF Service we use now are available. Of course, the concept of appdomain still exists in the city. I mentioned this because on Windows Azure, role is designed to allocate different types of applications to better suit their deployment methods.

2. Differences between worker role and web role

Simply put, the difference between woker role and web role lies in the deployment location. The project bound to the Web role is deployed on IIS, and the project bound to the worker role is deployed on an independent process. In general, we deploy websites or services for external use on the Web role, and deploy services or applications for internal calls in the worker role. This is not absolute. For example, the worker role can also deploy the WCF Service and publish HTTP-based services, but there are still many problems in configuration, next I will talk about the problems I have encountered.

3. Web role

Web role is relatively simple. There are too many tutorials on How to Create web role. I will put a link here to focus on my problems.

Question 1: How can I not read the configuration file in the roleentrypoint of the Web role?

We know that both web role and worker role will have a web/wokerrole. CS file in the bound project. The classes defined in this file inherit from roleentrypoint. This class will be called by the host process on azure. There are three rewrite methods, onstart, run, and onstop, which start and run processes respectively, the process is called at the end of the process. We can perform some configuration work on the host service in onstart. The host process I just mentioned is a PAAs process used to host our project to a virtual machine. It runs as a console-like process. Web role is deployed on IIS, so there is no conflict between them? In fact, this host Program has its own independent operation location. It reads app. config rather than Web. config. Therefore, the content of web. config cannot be read. Therefore, at least during the local test, we need to re-create an app. config to read the host process. The problem seems to have been solved, but in fact, when I publish the project to the actual cloud, I still cannot read app. config. I remotely boarded the instance and found that the Web role's hostpath is waiishost.exe, which runs at E: \ base \ x64. Therefore, he cannot read the data of APP. config. The hostentry of worker roleis called waworkerhost.exe. It is also in this folder. I guess it is because it is in the same way as the project to be deployed. It can read the data of APP. config. Web role does not have app. config by default, so there is no relevant logic in the host process to handle this problem. If any prawn knows the original cause, please let me know.

What should we do? The simplest method is: we have global. asax, so we can do onstart in application_start, so we can read the web. config information, whether used for WCF Service or other configuration items.

Question 2: How to use it in Web roleCodeDeploy a WCF Service?

The simplest way to deploy a WCF Service in a web application is to create the *. SVC file to host. However, the host WCF Service on our side has a uniform method, which uses code to host, in order to configure the host in worker role and in Web role. It is not as easy to expand as creating so many SVC files. To add one thing to Windows Azure, you must re-release it. Otherwise, the manually added items cannot always exist.

As mentioned above, we cannot deploy services in onstart in worker role, so we can only deploy services in global. asax. However, we must note that in roleentrypoint, the host WCF Service, service port, and host process will automatically add them to firewall, but global. asax does not help us with this, so we can only do it ourselves. We need to use the configuration node startup task. We need to use the system permission to add the port number we need to define in advance to the instance firewall when the host process host our project. Startup task allows us to run a batch file or other applications. Therefore, we only need to write a cmd or BAT file and write a script to run it. How to do, open this link: http://msdn.microsoft.com/en-us/library/gg456327.aspx

The script for adding a port is written as follows:

Netsh advfirewall Firewall add rule name = "internalendpoint" dir = in action = allow localport = 8888 protocol = TCP
Exit/B 0

4. Worker role

Question 1: How does one host the restful service or HTTP service exposed on the Internet in worker role?

The answer may disappoint everyone. For now, impossible! However, there is a condition that is made public to the outside, that is, the HTTP endpoint configured in the input is no problem. The reason is that Windows azure automatically helped us with load balance. At least the current Load balancer cannot be correctly mapped to the HTTP service in the worker role. However, this problem does not exist because of IIS in Web role. Whether it is a bug or not, it seems that we can only accept it reluctantly. We hope to fix this problem in the future.

I will update other problems at any time. If you have encountered any problems, I hope I can help you.

Next time I will talk about cloud storage.

 

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.