Azure的 - 不能以编程方式进行VIP交换 [英] Azure - Cannot programmatically perform VIP Swap

查看:122
本文介绍了Azure的 - 不能以编程方式进行VIP交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行交换部署操作,在C#中,在托管服务我在Azure云。我的code返回没有错误,但从未进行交换。

I am trying to perform a swap deployment operation, in C#, on a hosted service I have in the azure cloud. My code returns no errors, however, the swap is never performed.

我的code基于关闭样品code从如何做它使用GET列表服务运行微软的网站,但交换的部署使用POST。

My code is based off sample code from the Microsoft website on how to do a list services operation which uses GET, however swap deployment uses POST.

我是新来这个所以它可能我这样做是完全错误的方式。任何帮助是AP preciated。

I'm new to this so it's possible I'm doing this entirely the wrong way. Any help is appreciated.

下面是我的code迄今:

Here's my code so far:

public void swapDeployment()
{
    string operationName = "hostedservices";

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

    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>HealthMonitor - 21/10/2011 22:36:08</Production><SourceDeployment>SwapTestProject - 13/12/2011 22:23:20</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);
    }

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


            // Error shown at: using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            // Saying: The remote server returned an error: (404) Not Found.

编辑:我想我的主要问题是字符串XML = 行。其要求用于生产名称和部署名称。我想我只有一个!有人可以澄清一下,我应该在这里投入??

I think my main problem is the string xml= line. Its asking for the production name and the deployment name. I thought I only had one! Can someone clarify what I should be putting in here??

感谢

推荐答案

您要发送的外观错身。 (它缺少&lt;制造&GT; &LT; SourceDeployment方式&gt; 元素)另外,你没有表现出URL你使用。 404可能是因为URL是错误的。 (我希望像一个400坏请求主体。)

The body you're sending looks wrong. (It's missing the <Production> and <SourceDeployment> elements.) Also, you haven't shown the URL you're using. The 404 could be because the URL is wrong. (I would expect something like a 400 for the bad request body.)

如果你可以分享code的休息,可能会更容易调试。

If you could share the rest of the code, it may be easier to debug.

这篇关于Azure的 - 不能以编程方式进行VIP交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆