RoleEnviroment
クラスまたは同様のものを使用して C# コードからクラウド サービスのデプロイ名を取得する方法を探していmyservice.cloudapp.net
ますmyservice
。
どうやってやるの?
RoleEnviroment
クラスまたは同様のものを使用して C# コードからクラウド サービスのデプロイ名を取得する方法を探していmyservice.cloudapp.net
ますmyservice
。
どうやってやるの?
Gaurav は部分的に正しいです。Service Management API を使用する必要があります。用語に注意してください。展開名は通常、サービス コードの現在の展開を表す GUID です。ServiceName を探しています。Service Management API を使用して、 にリクエストを発行できますGet Hosted Service Properties
。応答オブジェクトのプロパティ ServiceName は、探している DNS プレフィックスです。
クラウド サービスの名前。この名前は DNS プレフィックス名であり、クラウド サービスへのアクセスに使用できます。たとえば、クラウド サービス名が MyService の場合、http://MyService.cloudapp.net を呼び出してクラウド サービスにアクセスできます。
Service Management REST API
クラウド サービス名を取得するには、 を使用する必要があります。操作は少し複雑です!
必要な手順は次のとおりです。
List Hosted Services
。Get Hosted Service Properties
。embed-detail=true
また、クエリ文字列パラメーターを必ず指定してください。PrivateID
取得する応答で、属性を見つけて、展開 ID と一致させる必要があります。私は長い間、次のようなことを可能にするコードを含むブログ投稿を書きました: http://gauravmantri.com/2012/03/16/programmatically-finding-deployment-slot-from-code-running-in- windows-azure/ .
async public Task<List<XDocument>> GetAzureServices()
{
String uri = String.Format("https://management.core.windows.net /{0}/services/hostedservices ", _subscriptionid);
List<XDocument> services = new List<XDocument>();
HttpClient http = GetHttpClient();
Stream responseStream = await http.GetStreamAsync(uri);
if (responseStream != null)
{
XDocument xml = XDocument.Load(responseStream);
var svcs = xml.Root.Descendants(ns + "HostedService");
foreach (XElement r in svcs)
{
XDocument vm = new XDocument(r);
services.Add(vm);
}
}
return services;
}
public HttpClient GetHttpClient()
{
WebRequestHandler handler = new WebRequestHandler();
string CertThumbprint = _certthumbprint;
X509Certificate2 managementCert = FindX509Certificate(CertThumbprint);
if (managementCert != null)
{
handler.ClientCertificates.Add(managementCert);
HttpClient httpClient = new HttpClient(handler);
httpClient.DefaultRequestHeaders.Add("x-ms-version", "2012-03-01");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
return httpClient;
}
return null;
}
private static X509Certificate2 FindX509Certificate(string thumbprint)
{
X509Store certificateStore = null;
X509Certificate2 certificate = null;
try
{
certificateStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certificateStore.Open(OpenFlags.ReadOnly);
var certificates = certificateStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
if (certificates.Count > 0)
{
certificate = certificates[0];
}
}
finally
{
if (certificateStore != null) certificateStore.Close();
}
return certificate;
}
subcriptionId と証明書の拇印を指定する必要があります