SALES: 1-800-867-1380
4 out of 8 rated this helpful - Rate this topic

List Cloud Services

Updated: April 3, 2014

The List Cloud Services operation lists the cloud services that are available under the specified subscription.

The List Cloud Services request may be specified as follows. Replace <subscription-id> with your subscription ID.

 

Method Request URI

GET

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

x-ms-version

Required. Specifies the version of the operation to use for this request. This header should be set to 2009-10-01 or higher. For more information about versioning headers, see Service Management Versioning.

x-ms-continuation-token

Optional. Specifies a continuation token that enables you to get the remainder of the response when there are more cloud services to list than can be returned in the allotted time. The value of this token is returned in the header of a previous response and will only be returned if additional cloud services need to be listed.

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

A successful operation returns status code 200 (OK). 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 comply with the HTTP/1.1 protocol specification.

 

Response Header Description

x-ms-request-id

Specifies a value that uniquely identifies a request made against the management service.

x-ms-continuation-token

Specifies a continuation token that enables you to get the remainder of the response when there are more cloud services to list than can be returned in the allotted time. If a large number of cloud services exist in the subscription, not all of them can be listed in a single response. You can use the token in this header in subsequent operation requests until all cloud services are returned.

The format of the response body is as follows:


<?xml version="1.0" encoding="utf-8"?>
  <HostedServices xmlns=”http://schemas.microsoft.com/windowsazure”>
    <HostedService>
      <Url>address-of-cloud-service</Url>
      <ServiceName>name-of-cloud-service</ServiceName>
      <HostedServiceProperties>
        <Description>description-of-cloud-service</Description>
        <AffinityGroup>name-of-affinity-group</AffinityGroup>
        <Location>location-of-cloud-service</Location>
        <Label>label-of-cloud-service</Label>
        <Status>status-of-cloud-service</Status>
        <DateCreated>date-created</DateCreated>
        <DateLastModified>date-modified</DateLastModified>
        <ExtendedProperties>
          <ExtendedProperty>
            <Name>name-of-property-name</Name>
            <Value>value-of-property</Value>
          </ExtendedProperty>
        </ExtendedProperties>
      </HostedServiceProperties>
      <DefaultWinRMCertificateThumbprint>certificate-thumbprint-for-winrm</DefaultWinRMCertificateThumbprint>
    </HostedService>
  </HostedServices>

The following table describes the elements of the response body.

 

Element name Description

Url

Specifies the request URI that is used to obtain information about the cloud service.

ServiceName

Specifies the name of the cloud service. This name is the DNS prefix name and can be used to access the service.

For example, if the service name is MyService you could access the access the service by calling: http://MyService.cloudapp.net

Description

Specifies the description of the cloud service.

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

AffinityGroup

Specifies the affinity group with which this cloud service is associated, if any. If the service is associated with an affinity group, the Location element is not returned.

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

Location

Specifies the geo-location of the cloud service in Azure, if the service is not associated with an affinity group. If a location is specified, the AffinityGroup element is not returned.

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

Label

Specifies the base-64 encoded identifier of the cloud service. This identifier can be used for your tracking purposes.

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

Status

Specifies the status of the cloud service. Possible values are:

  • Creating

  • Created

  • Deleting

  • Deleted

  • Changing

  • ResolvingDns

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

DateCreated

Specifies the date that the cloud service was created, in [4DigitYear]-[2DigitMonth]-[2DigitDay]T[2DigitHour]:[2DigitMinute]:[2DigitSecond]Z format. The date 2011-05-11T16:15:26Z is an example that could be returned by the DateCreated or DateLastModified elements.

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

DateLastModified

Specifies the date that the cloud service was last updated, in [4DigitYear]-[2DigitMonth]-[2DigitDay]T[2DigitHour]:[2DigitMinute]:[2DigitSecond]Z format. The date 2011-05-11T16:15:26Z is an example that could be returned by the DateCreated or DateLastModified elements

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

Name

Specifies the name of an extended cloud service property. 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

Represents 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.

DefaultWinRMCertificateThumbprint

Specifies the default certificate for a secure connection with WinRM. If a certificate thumbprint is not specified for WinRM when a Virtual Machine is deployed in a cloud service, a certificate is automatically created and the thumbprint is listed as the value of this element. For more information about defining WinRM, see Create Virtual Machine Deployment or Add Role.

If the x-ms-version is older than 2012-03-01, cloud services that contain virtual machine deployments will not be returned.

You can see the cloud services that exist in your subscription by looking in the Cloud Services section of the Management Portal. You can also get a list of cloud services by using the Get-AzureService cmdlet.

The following example console program lists the cloud services that exist in a subscription:


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

namespace ListCloudServices
{
  class Program
  {
    private const string Thumbprint = "thumbprint-of-management-certificate";
    private const string SubscriptionId = "subscription-identifier";
    private const string Version = "API-version-number";

    // 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
      string uriFormat = "https://management.core.windows.net/{0}/services/hostedservices";
      Uri uri = new Uri(String.Format(uriFormat, SubscriptionId));
      
      // Submit the request and get the response
      XDocument responseBody;
      HttpWebResponse response = InvokeRequest(uri, "GET", out responseBody);

      HttpStatusCode statusCode = statusCode = response.StatusCode;
      Console.WriteLine("The status of the operation: {0}\n\n", statusCode.ToString());
      Console.WriteLine(responseBody.ToString(SaveOptions.OmitDuplicateNamespaces));
      Console.Write("Press any key to continue:");
      Console.ReadKey();
    }
    // Process the request
    private static HttpWebResponse InvokeRequest(
      Uri uri,
      string method,
      out XDocument responseBody)
    {
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
      request.Method = method;
      request.Headers.Add("x-ms-version", Version);
      request.ClientCertificates.Add(Certificate);
      request.ContentType = "application/xml";

      responseBody = null;
      HttpWebResponse response;
      try
      {
        response = (HttpWebResponse)request.GetResponse();
      }
      catch (WebException ex)
      {
        response = (HttpWebResponse)ex.Response;
      }
      XmlReaderSettings settings = new XmlReaderSettings();
      settings.DtdProcessing = DtdProcessing.Ignore;
      if (response.ContentLength > 0)
      {
        using (XmlReader reader = XmlReader.Create(response.GetResponseStream(), settings))
        {
          try
          {
            responseBody = XDocument.Load(reader);
          }
          catch
          {
            responseBody = null;
          }
        }
      }
      response.Close();
      return response;
    }
    
    // Get the certificate
    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));
    }
  }
}

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.