Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:09:44+00:00 2026-05-27T10:09:44+00:00

I am trying to perform a swap deployment operation, in C#, on a hosted

  • 0

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.

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.

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

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.

EDIT: 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??

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:09:45+00:00Added an answer on May 27, 2026 at 10:09 am

    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.)

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to perform a pull from a remote repository, however the relevant code is
I'm trying perform a relatively basic TCP socket send/receive operation on Windows CE using
Trying to perform a single boolean NOT operation, it appears that under MS SQL
Trying to perform a nested object form. The page loads with no errors, but
I am trying to perform an animation on each bar in the chart, however
Am trying to perform a select into outfile, am having following errors My request:
I am trying to perform UPDATE action in Gridview(ASP.net). I have created a AccessDataSource
I'm trying to perform an inline operation where I need to sort a list
Trying to perform a very simple task here. I have an <ol> that contains
I'm trying to perform an operation on each character of a string which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.