Deploy and start the windowsservice program on windowsazure
After you have deployed a webrole on windowsazure, you find that as your usage increases, there will be a lot of invalid data in the database, so you plan to regularly Delete invalid data in the database. In this case, you need to deploy a small program on the azure Virtual Machine to implement this action. Of course, the small programs that implement this data deletion are diverse, and the deployment methods are also diverse, this article is just a virtual requirement to propose a method to deploy your own windowservice on windowsazure.
1. Add a windowsservice program to a webrole application.
For example, copy the compiled windowsservice program of agentservice.exe to the folder using a myappfolder, and add an installsvc. CMD file to install the program.
The content of the installsvc. CMD file is as follows:
% Windir % \ Microsoft. NET \ framework \ v4.0.30319 \ installutil.exe MyApp \ agentservice.exe
Net start agentservice
2. Set "Copy to output directory" for files in the MyApp folder to "Copy frequently ".
3. Start the windowsservice program.
Add a task to the. csdef file and use it to call the service installation script.
<?xml version="1.0" encoding="utf-8"?><ServiceDefinition name="WindowsAzureProject1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> <WebRole name="MvcWebRole1" vmsize="Small"> <Sites> <Site name="Web"> <Bindings> <Binding name="Endpoint1" endpointName="Endpoint1" /> </Bindings> </Site> </Sites> <Endpoints> <InputEndpoint name="Endpoint1" protocol="http" port="80" /> </Endpoints> <Imports> <Import moduleName="Diagnostics" /> </Imports> <Startup> <Task commandLine="MyApp\installsvc.cmd" executionContext="elevated" taskType="background" /> </Startup> </WebRole></ServiceDefinition>
Now we can upload the webrole to windowsazure, and register and start our windowsservice program on the instance virtual machine of the role.
In addition, adding the following nodes to the azure role node can improve the execution permission of the role to solve some problems due to insufficient permissions.
<WebRole name="MvcWebRole1" vmsize="Small"> <Runtime executionContext="elevated"></Runtime> </WebRole>
References:
Http://blogs.msdn.com/ B /luispanzano/archive/2011/03/19/instalar-un-servicio-windows-en-azure.aspx