首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows Azure服务管理API交换问题

Windows Azure服务管理API交换问题
EN

Stack Overflow用户
提问于 2011-12-15 00:42:15
回答 1查看 829关注 0票数 3

我对使用azure服务管理API比较陌生。我正在尝试使用交换部署操作,但一直收到无法修复的错误。我可能对这个操作完全错了,因为我对azure还不熟悉。任何帮助都是非常感谢的。

我得到的错误如下

代码语言:javascript
复制
<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>"

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

代码语言:javascript
复制
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();
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2011-12-15 01:07:59

这很可能是因为您的服务名称中有大写字母。它们都应该是小写的。然而,话虽如此...您为什么不使用示例客户端,而不使用自己的HTTP客户端?

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8508199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档