AutoscaleClient Constructor (SubscriptionCloudCredentials^)

 

Initializes a new instance of the AutoscaleClient class.

Namespace:   Microsoft.WindowsAzure.Management.Monitoring.Autoscale
Assembly:  Microsoft.WindowsAzure.Management.Monitoring (in Microsoft.WindowsAzure.Management.Monitoring.dll)

public:
AutoscaleClient(
	SubscriptionCloudCredentials^ credentials
)

Parameters

credentials
Type: Microsoft.WindowsAzure::SubscriptionCloudCredentials^

When you create a Windows Azure subscription, it is uniquely identified by a subscription ID. The subscription ID forms part of the URI for every call that you make to the Service Management API. The Windows Azure Service Management API use mutual authentication of management certificates over SSL to ensure that a request made to the service is secure. No anonymous requests are allowed.

The following example initializes a new AutoscaleClient object.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.Monitoring.Autoscale;
using Microsoft.WindowsAzure.Management.Monitoring.Autoscale.Models;
using Microsoft.WindowsAzure.Management.Monitoring.Utilities;
using System.Security.Cryptography.X509Certificates;

…

// The Windows Azure subscription ID.
string subscriptionId = "<subscription-ID>;        

// The thumbprint of the certificate.
string thumbprint = "<thumbprint>";

// Get the certificate from the local store.
X509Certificate2 cert =GetCertificate(StoreName.My, StoreLocation.LocalMachine, thumbprint);

// Create the autoscale client.
AutoscaleClient autoscaleClient = 
   new AutoscaleClient(new CertificateCloudCredentials(subscriptionId, cert));

…

public static X509Certificate2 GetCertificate(StoreName storeName, StoreLocation storeLocation, string thumbprint)
{
   var store = new X509Store(storeName, storeLocation);
   store.Open(OpenFlags.ReadOnly);

   try
   {
   StringBuilder builder = new StringBuilder(thumbprint.Length);
   foreach (char c in thumbprint)
   {
      if (char.IsLetterOrDigit(c))
      {
         builder.Append(c);
      }
   }

   string cleanThumbprint = builder.ToString();
   X509Certificate2Collection list = store.Certificates.Find(
      X509FindType.FindByThumbprint, cleanThumbprint, false);

   X509Certificate2 cert;
   if (list == null || list.Count != 1)
   {
      cert = null;
   }
   else
   {
      cert = list[0];
   }

   return cert;
   }
   finally
   {
      store.Close();
   }
}
Return to top
Show: