(0) exportieren Drucken
Alle erweitern

Create Cloud Service

Letzte Aktualisierung: April 2014

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.

 

Method Request URI

POST

https://management.core.windows.net/<subscription-id>/services/hostedservices

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 Description

Content-Type

Required. Set this header to application/xml.

x-ms-version

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 Dienstverwaltungs-Versionsverwaltung.

The format of the request body is as follows:

<?xml version="1.0" encoding="utf-8"?>
<CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure">
  <ServiceName>name-of-cloud-service</ServiceName>
  <Label>base64-encoded-label-of-cloud-service</Label>
  <Description>description-of-cloud-service</Description>
  <Location>location-of-cloud-service</Location>
  <AffinityGroup>name-of-affinity-group</AffinityGroup>
  <ExtendedProperties>
    <ExtendedProperty>
      <Name>name-of-property</Name>
      <Value>value-of-property</Value>
    </ExtendedProperty>
  </ExtendedProperties>
</CreateHostedService>

The following table describes the elements of the request body.

 

Element Name

Description

ServiceName

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.

Label

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.

Description

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

Location

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 Standorte auflisten.

AffinityGroup

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 Auflisten von Affinitätsgruppen.

Name

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.

Value

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.

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 Description

x-ms-request-id

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



    noteHinweis
    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 = "http://schemas.microsoft.com/windowsazure";
    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 = "https://management.core.windows.net/{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:");
      Console.ReadKey();
    }

    // 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.ClientCertificates.Add(Certificate);
      request.ContentType = "application/xml";
           
      HttpWebResponse response;

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

        response = (HttpWebResponse)request.GetResponse();
      }
      catch (WebException ex)
      {
        response = (HttpWebResponse)ex.Response;
      }
      response.Close();
      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>
      { 
        StoreLocation.CurrentUser, 
        StoreLocation.LocalMachine
      };

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

Anzeigen:
© 2014 Microsoft