Create Cloud Service

Create Cloud Service


Updated: June 29, 2015

The Create Cloud Service asynchronous operation creates a new cloud service in Microsoft Azure. For more information about cloud services and how you can use them, see What is a cloud service?.

Before you can run this operation, you must create a subscription and obtain the subscription identifier. For more information about creating an Azure subscription, see Welcome to Microsoft Azure. You can obtain the subscription identifier on the Settings page of the Management Portal. Create and upload a management certificate to authorize the operation. For more information, see Create and Upload a Management Certificate for Microsoft Azure.

The Create Cloud Service request is specified as follows. Replace <subscription-id> with your subscription ID.


Request URI


You must make sure that the request that is made to the management service is secure. For additional details, see Authenticating Service Management Requests.

The following table describes the request headers.

Request Header



Required. Set this header to application/xml.


Required. Specifies the version of the operation to use for this request. The value of this header must be set to 2010-10-28 or higher. For more information about versioning headers, see Service Management Versioning.

The format of the request body is as follows:

<?xml version="1.0" encoding="utf-8"?>
<CreateHostedService xmlns="">

The following table describes the elements of the request body.

Element Name



Required. Specifies the name for the cloud service. This name must be unique within Azure. This name is the DNS prefix name that is used to access the service. To verify the availability of a name, you can use Check Cloud Service Name Availability.


Required. Specifies the base-64-encoded identifier of the cloud service. The identifier can be up to 100 characters long. The label can be used for your tracking purposes.


Optional. Specifies the description of the cloud service. The description can be up to 1024 characters long.


Required if AffinityGroup is not specified. Specifies the location where the cloud service is created.

You must specify Location or AffinityGroup, but not both. To see the available locations, you can use List Locations.


Required if Location is not specified. Specifies the name of an existing affinity group that is associated with the subscription. You must specify Location or AffinityGroup, but not both. To see the available affinity groups, you can use List Affinity Groups.


Optional. Specifies the name of an extended cloud service property. The name can be up to 64 characters long, only alphanumeric characters and underscores are valid in the name, and it must start with a letter. Each extended property must have both a defined name and value. You can define a maximum of 50 extended properties.

The Name element is only available using version 2012-03-01 or higher.


Optional. Specifies the value of an extended cloud service property. The extended property value can be up to 255 characters long.

The Value element is only available using version 2012-03-01 or higher.


Optional. Specifies the DNS address to which the IP address of the cloud service resolves when queried using a reverse DNS query.

The ReverseDnsFqdn element is only available using version 2014-06-01 or higher.

The response includes an HTTP status code and a set of response headers.

A successful operation returns status code 201 (Created). For information about status codes, see Service Management Status and Error Codes.

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.

Response Header



A value that uniquely identifies a request made against the management service. For an asynchronous operation, you can call Get Operation Status with the value of the header to determine whether the operation is complete, has failed, or is still in progress.

You can also use the following resources to create a new cloud service:

Next step:

After you create a cloud service, the next step is to create a deployment. For more information see the following:

The following console application example shows you how to create a new cloud service. Replace the following variable values:

  • Thumbprint – with the thumbprint of a management certificate in your subscription

  • SubscriptionId – with the subscription identifier that you obtained from the Management Portal

  • ServiceName – with the name that you want to use for the new cloud service

  • Location – with the geo-location where you would like to locate the cloud service


    You can use List Locations to obtain the appropriate location.

using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.IO;

namespace CreateCloudService
  class Program
    private static XNamespace wa = "";
    private const string Thumbprint = "thumbprint-of-certificate";
    private const string SubscriptionId = "identifier-of-subscription";
    private const string ServiceName = "name-of-cloud-service";
    private const string Location = "location-of-cloud-service";
    private const string Version = "2013-08-01";

    // Gets or sets the certificate that matches the Thumbprint value.
    private static X509Certificate2 Certificate { get; set; }

    static void Main(string[] args)
      Certificate = GetStoreCertificate(Thumbprint);

      // Create the URI for the request
      string uriFormat = "{0}/services/hostedservices";
      Uri uri = new Uri(String.Format(uriFormat, SubscriptionId));

      // Base-64 encode the label of the cloud service
      byte[] bytes = System.Text.Encoding.UTF8.GetBytes(ServiceName);
      string base64Label = Convert.ToBase64String(bytes);

      // Create the request body
      XDocument requestBody = new XDocument(
        new XDeclaration("1.0", "UTF-8", "no"),
        new XElement(wa + "CreateHostedService",
          new XElement(wa + "ServiceName", ServiceName),
          new XElement(wa + "Label", base64Label),
          new XElement(wa + "Location", Location)));

      // Submit the request and get the response
      HttpWebResponse response = InvokeRequest(uri, "POST", requestBody);

      HttpStatusCode statusCode = response.StatusCode;
      Console.WriteLine("The status of the operation: {0}", statusCode.ToString());
      Console.Write("Press any key to continue:");

    // Set the request headers and submit the request
    private static HttpWebResponse InvokeRequest(
      Uri uri,
      string method,
      XDocument requestBody)
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
      request.Method = method;
      request.Headers.Add("x-ms-version", Version);
      request.ContentType = "application/xml";
      HttpWebResponse response;

        byte[] byteArray = null;
        byteArray = Encoding.UTF8.GetBytes(requestBody.ToString());
        Stream stream = request.GetRequestStream();
        stream.Write(byteArray, 0, byteArray.Length);

        response = (HttpWebResponse)request.GetResponse();
      catch (WebException ex)
        response = (HttpWebResponse)ex.Response;
      return response;

    // Gets the certificate matching the thumbprint from the local store.
    // Throws an ArgumentException if a matching certificate is not found.
    private static X509Certificate2 GetStoreCertificate(string thumbprint)
      List<StoreLocation> locations = new List<StoreLocation>

      foreach (var location in locations)
        X509Store store = new X509Store("My", location);
          store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
          X509Certificate2Collection certificates = store.Certificates.Find(
            X509FindType.FindByThumbprint, thumbprint, false);
          if (certificates.Count == 1)
            return certificates[0];
      throw new ArgumentException(string.Format(
        "A Certificate with Thumbprint '{0}' could not be located.",
© 2016 Microsoft