This article is a part of a series of articles related to one of the Azure Compute options, “Cloud Services”.
In this article, we will learn about the files that get created when we create an Azure Cloud Service Project.
- Roles
- As we have created an empty Azure Cloud Service Project, we have an empty “Roles” folder. In general, this folder contains all the codebase related to the Web Roles and the Worker Roles.
- XML Files
- ServiceConfiguration.Cloud.cscfg
- ServiceConfiguration.Local.cscfg
- ServiceDefinition.csdef
Let’s examine each of the above XML files individually.
ServiceDefinition.csdef
This file is called Service definition and contains all the details about the Cloud Service. It contains the details of Web Role(s) and Worker Role(s). This file defines the service model of the application. Based on the information provided in this file, the App Fabric Controller creates everything required for the application.
- The size of the Virtual Machine instance where the roles are hosted.
- The endpoints information (We will learn more about these endpoints in upcoming articles).
- Traffic rules (We will learn more about these in upcoming articles).
- Other configuration settings, like connection strings etc.
Below are the default settings that are created when the Azure Cloud Service project is created.
- <?xml version="1.0" encoding="utf-8"?>
- <ServiceDefinition name="HelloWorldCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
- <WebRole name="FrontEnd.Web" vmsize="Small">
- <Sites>
- <Site name="Web">
- <Bindings>
- <Binding name="Endpoint1" endpointName="Endpoint1" /> </Bindings>
- </Site>
- </Sites>
- <ConfigurationSettings>
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> </ConfigurationSettings>
- <Endpoints>
- <InputEndpoint name="Endpoint1" protocol="http" port="80" /> </Endpoints>
- </WebRole>
- <WorkerRole name="WorkerRole1" vmsize="Small">
- <ConfigurationSettings>
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> </ConfigurationSettings>
- </WorkerRole>
- </ServiceDefinition>
ServiceConfiguration.cscfg
This file is called as Service Configuration file and contains the configuration details of the Web Role(s) and Worker Role(s). Service Configuration files are similar to Web.Config file (for Web Apps) and App.Config files (for Windows Apps),
- The OS family of the Virtual Machine where the Roles are hosted.
- The OS Version of the Virtual Machines.
- The number of instances in which the Roles are to be hosted.
If you have noticed clearly, there are two versions of the Service Configuration files in the root folder of the project.
- ServiceConfiguration.Cloud.cscfg
- ServiceConfiguration.Local.cscfg
One is tagged for Cloud and the other is tagged to be used in the local environment. These are two files that are created by default. We can also create additional files for our other environments, like Staging, Testing etc.
Below are the default settings that are created when the Azure Cloud Service project is created.
- <?xml version="1.0" encoding="utf-8"?>
- <ServiceConfiguration serviceName="HelloWorldCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
- <Role name="FrontEnd.Web">
- <Instances count="1" />
- <ConfigurationSettings>
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings>
- </Role>
- <Role name="WorkerRole1">
- <Instances count="1" />
- <ConfigurationSettings>
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings>
- </Role>
- </ServiceConfiguration>
Few important points to note are:
- If there are any changes to the Service Definition file, after your Cloud Service has been deployed, you have to re-deploy your Cloud Service package. (We will learn more about the Cloud Service package in my upcoming articles).
- If there are any changes to the Service Configuration files after you deploy the Cloud Service, you have no need to re-deploy your entire Cloud Service package. You can simply upload your Cloud Service Configuration (.cscfg) file or simply make that change in the portal directly.
If you have observed carefully, the configuration settings are also defined in the Service Definition file. So, you cannot simply add or remove these settings. Below is the setting name that I am talking about Service Definition File.
- <ConfigurationSettings>
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /> </ConfigurationSettings> Service Configuration File – The following tag is being referred in both the Web and Worker Roles.
- <ConfigurationSettings>
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> </ConfigurationSettings>
The setting name in the Service Configuration file should be the same that is specified in the Service Definition file. Let’s try to comment out the following tag in the Service Definition file and see what happens.
- <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
Below is the error that I got after commenting out the above line in the Service Definition file.
So, in order to add a new Configuration setting in the Service Configuration file, you have to first add the name of that setting in the Service Definition file and then use the same in the Service Configuration file.
Hope you enjoyed the article. Your feedback is much appreciated.