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?
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
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:
List Hosted Services
operation.Get Hosted Service Properties
. Also make sure that you provide embed-detail=true
query string parameter.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/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With