AlertsClient Constructor (SubscriptionCloudCredentials^)
Initializes a new instance of the AlertsClient class.
Assembly: Microsoft.WindowsAzure.Management.Monitoring (in Microsoft.WindowsAzure.Management.Monitoring.dll)
Parameters
- credentials
-
Type:
Microsoft.WindowsAzure::SubscriptionCloudCredentials^
When you create an 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 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 AlertsClient object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.Monitoring.Alerts;
using Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models;
using Microsoft.WindowsAzure.Management.Monitoring.Utilities;
using System.Security.Cryptography.X509Certificates;
…
// The 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 alerts client.
AlertsClient alertsClient =
new AlertsClient(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();
}
}
Show: