Windows Azure Service Management API to delete deployment from Azure Hosted Service using c#

Continuing with same let’s have a look at deleting deployment from windows azure using service management API via c#.
The configuration and other related settings will be same as stated in previous post. Code for deleting deployment from windows azure hosted service is as follows –
X509Certificate2 cert = new X509Certificate2(Server.MapPath(CertificatePath), CertificatePassword);
var serviceManagment = ServiceManagementHelper.CreateServiceManagementChannel(EndpointConfigurationName, cert);

HostedService hostedService = serviceManagment.GetHostedServiceWithDetails(SubscriptionId, lblHostedServiceName.Text, true);

foreach (Deployment deployment in hostedService.Deployments)
{
UpdateDeploymentStatusInput u = new UpdateDeploymentStatusInput();
u.Status = "Suspended";
serviceManagment.UpdateDeploymentStatus(SubscriptionId, hostedService.ServiceName, deployment.Name, u);
while (deploymentStatus != "Suspended")
{
Thread.Sleep(20000);
HostedService tempHostedService = serviceManagment.GetHostedServiceWithDetails(SubscriptionId, lblHostedServiceName.Text, true);
//retrieve current deployment to know its latest status
Deployment tempDeployment = tempHostedService.Deployments.Find(delegate(Deployment d) { return d.Name == deployment.Name; });
deploymentStatus = tempDeployment.Status;
}
                        serviceManagment.DeleteDeployment(SubscriptionId, hostedService.ServiceName, deployment.Name);
}

Hope this helps.
Cheers…
Happy Coding!!!

Comments

Popular posts from this blog

The request has both SAS authentication scheme and 'Bearer' authorization scheme. Only one scheme should be used

Getting Started with Logic Apps - AS2

How to Debug and Trace request in Azure APIM - Portal, Postman, RequestBin