1: const string getDeploymentUrl = "https://management.core.windows.net/{0}/services/hostedservices/{1}/deployments/{2}";
2: const string getDeploymentVersion = "2012-03-01";
3:
4: public static Deployment GetDeployment(Guid subscriptionId, string serviceName, string deploymentName, X509Certificate2 cert)
5: {
6: Uri uri = new Uri(String.Format(getDeploymentUrl, subscriptionId, serviceName, deploymentName));
7:
8: HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
9: request.Method = "GET";
10: request.Headers.Add("x-ms-version", getDeploymentVersion);
11: request.ClientCertificates.Add(cert);
12: request.ContentType = "application/xml";
13:
14: XDocument responseBody = null;
15: HttpStatusCode statusCode;
16: HttpWebResponse response;
17: try
18: {
19: response = (HttpWebResponse)request.GetResponse();
20: }
21: catch (WebException ex)
22: {
23: // GetResponse throws a WebException for 400 and 500 status codes
24: response = (HttpWebResponse)ex.Response;
25: }
26: statusCode = response.StatusCode;
27: if (response.ContentLength > 0)
28: {
29: using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
30: {
31: responseBody = XDocument.Load(reader);
32: }
33: }
34: response.Close();
35: if (statusCode.Equals(HttpStatusCode.OK))
36: {
37: XNamespace wa = "http://schemas.microsoft.com/windowsazure";
38: XElement dep = responseBody.Element(wa + "Deployment");
39: Deployment deployment = new Deployment
40: {
41: Name = dep.Element(wa + "Name").Value,
42: Slot = (DeploymentSlot)Enum.Parse(typeof(DeploymentSlot), dep.Element(wa + "DeploymentSlot").Value),
43: PrivateID = dep.Element(wa + "PrivateID").Value,
44: Status = (DeploymentStatus)Enum.Parse(typeof(DeploymentStatus), dep.Element(wa + "Status").Value),
45: Label = dep.Element(wa + "Label").Value,
46: Url = new Uri(dep.Element(wa + "Url").Value),
47: Configuration = dep.Element(wa + "Configuration").Value,
48: Roles = (from r in dep.Element(wa + "RoleInstanceList").Elements(wa + "RoleInstance")
49: select new RoleInstance
50: {
51: RoleName = r.Element(wa + "RoleName").Value,
52: InstanceName = r.Element(wa + "InstanceName").Value,
53: Size = (InstanceSize)Enum.Parse(typeof(InstanceSize), r.Element(wa + "InstanceSize").Value),
54: Status = (InstanceStatus)Enum.Parse(typeof(InstanceStatus), r.Element(wa + "InstanceStatus").Value)
55:
56: }).ToList()
57: };
58:
59: return deployment;
60: }
61: else
62: {
63: //TODO: return some error
64: }
65: return null;
66: }