c# - Windows Azure 服务管理 API 交换问题

标签 c# api azure cloud swap

我对使用 Azure 服务管理 API 比较陌生。我正在尝试使用交换部署操作,但我不断收到无法修复的错误。由于我是 azure 的新手,我可能会完全错误地进行此操作。非常感谢任何帮助。

我收到的错误如下

<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Code>ResourceNotFound</Code><Message>The resource service name hostedservices is not supported. If it is a new partner service please ensure that the service is registered in RDFE.</Message></Error>"

这是我的代码,我在其中指定了异常发生的位置

public void swapDeployment()
    {

        String operationName = "hostedservices";
        String prodName = "HealthMonitor - 21/10/2011 22:36:08";
        String sourceName = "SwapTestProject - 13/12/2011 22:23:20";

        Uri swapURI = new Uri("https://management.core.windows.net/"
                          + subscriptionId
                          + "/services/"
                          + "hostedservices"
                          + "/stevenRiordanHello/");

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(swapURI);

        request.Headers.Add("x-ms-version", "2009-10-01");
        request.Method = "POST";
        request.ContentType = "application/xml";

        String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Swap xmlns=\"http://schemas.microsoft.com/windowsazure\"><Production>"+prodName+"/Production><SourceDeployment>"+sourceName+"</SourceDeployment></Swap>";
        byte[] bytes = Encoding.UTF8.GetBytes(xml);
        request.ContentLength = bytes.Length;

        X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);

        try
        {
            certStore.Open(OpenFlags.ReadOnly);
        }
        catch (Exception e)
        {
            if (e is CryptographicException)
            {
                Console.WriteLine("Error: The store is unreadable.");
            }
            else if (e is SecurityException)
            {
                Console.WriteLine("Error: You don't have the required permission.");
            }
            else if (e is ArgumentException)
            {
                Console.WriteLine("Error: Invalid values in the store.");
            }
            else
            {
                throw;
            }
        }

        X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
        certStore.Close();

        if (0 == certCollection.Count)
        {
            throw new Exception("Error: No certificate found containing thumbprint " + thumbprint);
        }

        X509Certificate2 certificate = certCollection[0];

        request.ClientCertificates.Add(certificate);

        using (Stream requestStream = request.GetRequestStream())
        {
            requestStream.Write(bytes, 0, bytes.Length);
        }
        try
        {
            //exception is caught at the end of the line below
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    string message = String.Format("POST failed. Received HTTP {0}", response.StatusCode);
                    throw new ApplicationException(message);
                }
            }
        }
        catch(WebException e)
        {
            StreamReader sr = new StreamReader(e.Response.GetResponseStream());
            string errorText = sr.ReadToEnd();
        }
    }

最佳答案

这可能是因为您的服务名称中包含大写字母。它应该全部小写。然而,话虽这么说...您是否有理由不只使用示例客户端而不是滚动自己的 HTTP 客户端?

更新此答案:您必须拥有有效的 XML,而且它的参数也是部署名称。这是很少使用的东西之一。它通常是 GUID。真正获取此信息的唯一方法是使用 GetDeployment调用或GetHostedService调用了解有关部署的详细信息。在该响应中,您将看到该名称。该名称绝对与您提供的任何名称不同(我认为您正在使用标签)。

关于c# - Windows Azure 服务管理 API 交换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8508199/

相关文章:

c# - 如何在Ravendb中创建复合索引

api - 具有单个服务器的 OAuth 2.0

visual-studio - Azure Web 应用程序网关性能与负载测试

java - 带有 Matlab 的 "nativemvm library"Engine API Java 错误

python-3.x - 由于 spacy-transformer 模块,Azure 函数应用程序部署失败

c# - 尝试获取用于访问自定义 api 的 token 时出现 MSAL 错误消息 AADSTS65005

c# - 为什么foreach循环里面的switch只执行一次

c# - 这个颜色矩阵如何使图像变成黑白的?

c# - 将 stringbuilder 中的 null 值转换为 "not available"字符串

php - WooCommerce Rest API 返回 404 未找到