【问题标题】:Windows Azure service mgmt API Swap issueWindows Azure 服务管理 API 交换问题
【发布时间】:2011-12-14 16:42:14
【问题描述】:

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

我得到的错误如下

<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();
        }
    }

【问题讨论】:

    标签: c# api azure cloud swap


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复,我将服务名称更改为全部小写,但仍然出现相同的错误。我的代码基于此处 msdn.microsoft.com/en-us/library/windowsazure/ee460782.aspx 的代码,其中列出了您的托管服务。此代码对我有用。但是我知道的代码是针对 GET 的,而交换部署操作是 POST。
    • 好的,是不是因为无效的XML?请参阅:“”+prodName+"/Production>" 仍然...为什么不在 csmanage 中使用 cmdlet 或示例客户端?
    • 哦,为发现这一点而欢呼,但我仍然遇到同样的错误。而且我只是一名学生,我实际上并不了解“csmanage 中的 cmdlet 或示例客户端”
    • csmanage 在这里 (code.msdn.microsoft.com/windowsazure/…) 或使用此处的 cmdlet:wappowershell.codeplex.com
    猜你喜欢
    • 2012-08-28
    • 2013-05-22
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    相关资源
    最近更新 更多