Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the service name from code for a Azure Cloud Service?

I am looking for a way to get the deployment name for a cloud service from C# code using RoleEnviroment class or something similar so that if my service is deployed at myservice.cloudapp.net I get myservice.

How can I do that?

like image 717
Poul K. Sørensen Avatar asked May 27 '13 16:05

Poul K. Sørensen


2 Answers

Gaurav is partially correct. You will have to use the Service Management API. Be careful with your terminology - Deployment Name is typically a GUID representing the current deployment of the service code. You are looking for the ServiceName. Using the Service Management API, you can issue a request to Get Hosted Service Properties. The property ServiceName in the response object is the DNS prefix you are looking for:

The name of the cloud service. This name is the DNS prefix name and can be used to access the cloud service. For example, if the cloud service name is MyService you could access the cloud service by calling: http://MyService.cloudapp.net

like image 143
viperguynaz Avatar answered Nov 14 '22 01:11

viperguynaz


You would need to make use of Service Management REST API to get the cloud service name. The operation is a bit convoluted one!

Here're the steps you would need to do:

  1. Get the deployment id. This you will be able to get from RoleEnvironment.
  2. Next you fetch the list of all cloud services in your subscription. For this you would need to perform List Hosted Services operation.
  3. Then for each cloud service, you would need to get the properties. For this you would need to perform Get Hosted Service Properties. Also make sure that you provide embed-detail=true query string parameter.
  4. In the response you'll get, you would need to find the PrivateID attribute and match it with your deployment id.

I wrote a blog post long time back which has some code to let you do something like this: http://gauravmantri.com/2012/03/16/programmatically-finding-deployment-slot-from-code-running-in-windows-azure/.

like image 35
Gaurav Mantri Avatar answered Nov 14 '22 00:11

Gaurav Mantri