Eksportuj (0) Drukuj
Rozwiń wszystko
EN
Ta zawartość nie jest dostępna w wymaganym języku. Wersja w języku angielskim znajduje się tutaj.

Add Service Certificate

Updated: September 30, 2014

The Add Service Certificate asynchronous operation adds a certificate to a cloud service.

The Add Service Certificate request may be specified as follows. Replace <subscription-id> with the subscription ID, and <service-name> with the DNS prefix name of the cloud service.

 

Method Request URI

POST

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

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. This header should be set to 2009-10-01 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"?>
<CertificateFile xmlns=”http://schemas.microsoft.com/windowsazure”>
  <Data>base64-encoded-file</Data>
  <CertificateFormat>file-format</CertificateFormat>
  <Password>pfx-file-password</Password>
</CertificateFile>

The following table describes the elements in the request body.

 

Element name Description

Data

Required. Specifies the base-64 encoded form of the .pfx or .cer file.

noteNote
The service certificate is added as either a .pfx or .cer file. When retrieving the service certificate using the List Service Certificates or Get Service Certificate operation, only the public portion of the certificate is returned as a .cer file.

CertificateFormat

Required. Specifies the format of the service certificate.

Possible values are:

  • pfx

  • cer

Password

Specifies the password for a .pfx certificate. A .cer certificate does not require a password.

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

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

The following method constructs a request to add a service certificate, submits the request to the service, and returns the request ID.


public static string AddCertificate(string subscriptionId, string applicationName, X509Certificate2 managementCertificate, string pfxPath, string password)
{
    // Construct the request URI.    var req = (HttpWebRequest)WebRequest.Create(string.Format("https://management.core.windows.net/{0}/services/hostedservices/{1}/certificates", subscriptionId, applicationName));

    // Set the request method and the content type for the request.
    req.Method = "POST";
    req.ContentType = "application/xml";

    // Add the x-ms-version header.
    req.Headers.Add("x-ms-version", "2009-10-01");

    // Add the certificate.
    req.ClientCertificates.Add(managementCertificate);

    // Construct the request body.
    using (var writer = new StreamWriter(req.GetRequestStream()))
    {
        writer.Write(string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
                                   <CertificateFile xmlns=""http://schemas.microsoft.com/windowsazure"">
                                   <Data>{0}</Data>
                                   <CertificateFormat>pfx</CertificateFormat>
                                   <Password>{1}</Password>
                                   </CertificateFile>", 
                                   Convert.ToBase64String(File.ReadAllBytes(pfxPath)), 
                                   password));
    }

    // Submit the request and return the request ID.
    return req.GetResponse().Headers["x-ms-request-id"];
}

Pokaż:
© 2014 Microsoft