Using the Windows Azure Service Management Library NuGet package, C # code to get the package:
private static X509Certificate2 GetCertificate(string storeName, string thumbprint) { var store = new X509Store(storeName); store.Open(OpenFlags.ReadOnly); return store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true)[0]; } public static void ExportPackage(X509Certificate2 certificate, string subscriptionId, string serviceName, string deploymentName, string containerUri) { var managementService = ServiceManagementHelper.CreateServiceManagementChannel("WindowsAzureEndPoint", certificate); try { managementService.GetPackage( subscriptionId, serviceName, deploymentName, containerUri, true ); } catch (Exception ex) { System.Net.WebException exception = ex.InnerException as System.Net.WebException; if (exception != null) { string responseText; using (var reader = new System.IO.StreamReader(exception.Response.GetResponseStream())) { responseText = reader.ReadToEnd(); Console.WriteLine("ERROR:" + exception); Console.WriteLine(responseText); } } } }
My problem, however, is that no matter what I pass as the Uri container, I return 400 Bad request - the value of the parameter "something.blob.core.windows.net/somecontainer"; The specified for the parameter "ContainerUriString" is invalid.
Update: my problem was due to a storage container owned by another subscription that was clearly not working. I made sure that the container belongs to the same subscription, and voila!
Refresh . This code assumes the following app.config file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /> </startup> <system.serviceModel> <bindings> <webHttpBinding> <binding name="WindowsAzureServiceManagement_WebHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> <readerQuotas maxStringContentLength="1048576" maxBytesPerRead="131072"/> <security mode="Transport"> <transport clientCredentialType="Certificate"/> </security> </binding> </webHttpBinding> </bindings> <client> <endpoint name="WindowsAzureEndPoint" address="https://management.core.windows.net" binding="webHttpBinding" bindingConfiguration="WindowsAzureServiceManagement_WebHttpBinding" contract="Microsoft.Samples.WindowsAzure.ServiceManagement.IServiceManagement" /> </client> </system.serviceModel> </configuration>
or, alternatively, for LinqPad users, you can configure the embedded web service as follows:
var b = new WebHttpBinding(WebHttpSecurityMode.Transport); b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; var address = new EndpointAddress("https://management.core.windows.net"); var managementService = ServiceManagementHelper.CreateServiceManagementChannel(b, address.Uri, certificate);
Typical Usage:
X509Certificate2 certificate = GetCertificate("My", "NNNNNNNNNNNNN"); ExportPackage(certificate, "00000000-0000-0000-0000-000000000000", "yourservice", "00000000000000000000000000000000", "https://yourstorage.blob.core.windows.net/container");