我有一個帶有Web角色和工作者角色的Windows Azure雲服務。我建立了一個網站,允許我針對雲服務執行各種管理功能(停止/啓動,重啓實例,添加實例,移除實例)。所有的功能都是通過web API執行的。我的問題是,當我添加一個Web角色的實例時,工作者角色會重新啓動。請注意,如果通過Azure門戶添加實例,則不會發生這種情況。代碼在所有其他方面正常運行。 任何想法如何做到這一點,以便只有受影響的角色回收而不是回收所有角色?當添加Web角色實例時,Azure Worker角色重新啓動
我的代碼:
public void AddInstance()
{
XDocument configDoc = this.GetDeploymentConfiguration();
var ns = configDoc.Root.GetDefaultNamespace();
configDoc.Root
.Elements(ns + "Role")
.FirstOrDefault(r => r.Attribute("name").Value.ToLower() == this.RoleName.ToLower())
.Element(ns + "Instances")
.Attribute("count")
.Value = (int.Parse(configDoc.Root
.Elements(ns + "Role")
.FirstOrDefault(r => r.Attribute("name").Value.ToLower() == this.RoleName.ToLower())
.Element(ns + "Instances")
.Attribute("count")
.Value) + 1).ToString();
string encodedString = Convert.ToBase64String(Encoding.UTF8.GetBytes(configDoc.ToString()));
this.SetDeploymentConfig(encodedString);
}
public XDocument GetDeploymentConfiguration()
{
string uri = string.Format(this.servicePropertiesOperationFormat, this.subscriptionID, this.serviceName, "production", "");
ServiceManagementOperation operation = new ServiceManagementOperation(this.thumbprint, this.versionID);
var xdoc= operation.Invoke(uri);
var myelm = xdoc.Element(wa + "Deployment").Element(wa + "Configuration");
var mystring= Encoding.UTF8.GetString(Convert.FromBase64String(myelm.Value));
return XDocument.Parse(mystring);
}
public string SetDeploymentConfig(string configurationFile)
{
string uri = string.Format(this.servicePropertiesOperationFormat, this.subscriptionID, this.serviceName, "production", "/?comp=config");
ServiceManagementOperation operation = new ServiceManagementOperation(this.thumbprint, this.versionID);
string payloadString = string.Format(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<ChangeConfiguration xmlns=""http://schemas.microsoft.com/windowsazure"">
<Configuration>{0}</Configuration>
</ChangeConfiguration>", configurationFile);
XDocument payload = XDocument.Parse(payloadString);
return operation.Invoke(uri, payload);
}
您的角色是否共享升級域?考慮這裏解釋的詳細信息:https://msdn.microsoft.com/en-us/library/azure/hh472157.aspx – 2015-03-03 07:02:14