Download uploaded cspkg file from Azure

后端 未结 3 531
无人及你
无人及你 2020-12-20 17:37

Can I download the cspkg from Azure that I uploaded (rather than reuploading new package)?

The scenario is -

I need to add files into existing website - let

3条回答
  •  臣服心动
    2020-12-20 18:37

    Using the Windows Azure Service Management Library NuGet Package, the C# code to get the package becomes:

    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 /*overwriteExisting*/);
        }
        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 in as the containerUri, I get back 400 Bad request - Parameter value 'something.blob.core.windows.net/somecontainer'; specified for parameter 'ContainerUriString' is invalid.

    Update: my problem was due to the storage container belonging to a different subscription - that was obviously not working. I made sure the container belonged to the same subscription, and voila!

    Update: This code assumes the following app.config:

    
    
     
        
    
    
        
            
                
                    
                    
                        
                    
                
            
        
        
            
        
    
    
    

    or, alternatively, for LinqPad users, you can configure web service inline 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 use:

    X509Certificate2 certificate = GetCertificate("My", "NNNNNNNNNNNNN");
    ExportPackage(certificate,
                "00000000-0000-0000-0000-000000000000",
                "yourservice",
                "00000000000000000000000000000000",
                "https://yourstorage.blob.core.windows.net/container");
    

提交回复
热议问题