Tag: azure worker roles

AZURE:在workerrole中异步运行Run()

我有一个异步任务。 async Task UploadFiles() { } 我想在azure workerrole的Run()方法中对UploadFiles()调用’await’。 但’await’仅适用于声明为异步的方法。 所以我可以像下面那样使Run()方法异步: public override void Run() { UploadFiles(); } 至 public async override void Run() { await UploadFiles(); }

如何在Worker角色实例上成功编辑代码中的防火墙规则?

我正在尝试一些在本地工作的代码但它在我的云实例上不起作用。 我假设它可能与权限相关,但我还无法修复它。 这是我在本地调试我的工作者角色时的工作原理,但是当它发布时没有任何反应(现在正在暂存)。 string strCmdText = string.Format(“advfirewall firewall add rule name=\”BlockU\” protocol=any dir=in action=block remoteip={0}”, ip); ProcessStartInfo psi = new ProcessStartInfo(“netsh.exe”, strCmdText); psi.RedirectStandardOutput = true; psi.UseShellExecute = false; psi.CreateNoWindow = true; try { Process.Start(psi); } catch (Exception ex) { Debug.WriteLine(ex.Message); } 我也试过用 psi.Verb = “runas”; 但这也没有帮助。 最后我尝试了防火墙api。 这也在本地工作,但在最后一行上抛出了访问被拒绝错误。 INetFwRule2 inboundRule = (INetFwRule2)Activator.CreateInstance(Type.GetTypeFromProgID(“HNetCfg.FWRule”)); inboundRule.Enabled = true; […]

获取服务以在Azure辅助角色中运行

我有一个Windows服务,我需要迁移到Azure作为工作者角色。 在我的Azure解决方案中,一切都很好。 但是,当我上传所有内容时,只会启动Web角色。 工作者角色实例在以下两种状态之间卡住循环而不启动。 等待角色开始…… 稳定角色…… 由于实例未能启动,我怀疑我的问题出现在我的WorkerRole.cs代码中。 您将在下面找到该代码。 我还提供了服务代码,以防它与问题相关。 我做错了什么? 这是我的WorkerRole.cs文件: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; using System.Threading; using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.Diagnostics; using Microsoft.WindowsAzure.ServiceRuntime; using Microsoft.WindowsAzure.StorageClient; using System.ServiceProcess; namespace SBMWorker { public class WorkerRole : RoleEntryPoint { public override void Run() { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new […]

在azure worker角色中使用QueueClient.OnMessage

我有一个Azure辅助角色,负责检查4个服务总线队列。 目前,我只是循环方法来手动检查队列。 while(true) { //loop through my queues to check for messages } Azure SDK 2.0具有监听消息而不是轮询消息的能力。 但是我见过的每个例子都使用Console.ReadKey()的控制台应用程序。 有没有办法让工人角色坐下来等待消息呢? 我试过了: public override void Run() { _queueProcessors.ForEach(x => x.OnMessage(Process); } 其中_queueProcessors是QueueClients的列表,而Process是处理消息的私有方法。 但是,worker角色会注册它们然后重新启动。 所以任何人都知道如何让队列客户端坐下来等待消息?

Azure API服务器无法validation请求

我有一个任务(我尝试使用worker角色并上传控制台应用程序并运行.exe),该任务应该每天运行一次,并收集我的一些虚拟机的Azure Metrics。 这在本地完美无缺,但在云服务上我得到此错误: 未处理的exception:Microsoft.WindowsAzure.CloudException:ForbiddenError:服务器无法validation请求。 validation证书是否有效并与此订阅相关联。 在Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSucces …等 发生这种情况的路线是: MetricDefinitionListResponse metricListResponse = metricsClient.MetricDefinitions.List(resourceId, null, nspace); 这是我的代码的一部分: string subscriptionId = “fc4xxxx5-835c-xxxx-xxx-xxxxxxx”; // The thumbprint of the certificate. string thumbprint = “‎f5 b4 xxxxxxxx f7 c2”; // Get the certificate from the local store. //X509Certificate2 cert = GetCertificate(StoreName.My, StoreLocation.LocalMachine, thumbprint); //cert = GetCertificate(StoreName.My, StoreLocation.CurrentUser, thumbprint) ?? new X509Certificate2((“manageAzure.cer”)); […]

‘Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment’的类型初始值设定项引发exception

我正在尝试使用Windows Azure缓存在MVC4应用程序中存储会话。 我按照Link的步骤构建了一个应用程序,但是当我尝试使用下面的代码行创建DataCache的对象时。 DataCache cache = new DataCache(“default”); 发生错误: 找不到Microsoft.WindowsAzure.ServiceRuntime.dll或版本不匹配,我将Windows Azure Emulator版本更新为2.0.0并使用NuGet软件包安装程序安装WindowsAzure.Caching软件包版本2.0.0.0。 现在错误更改为“Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment的类型初始化程序”引发exception。 我使用Windows 8 with VS2012 and Windows Azure Emulator version 2.0.0. 如果有人能帮助我,我将不胜感激。 InnerException Message: The type initializer for ‘Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment’ threw an exception. Source: Microsoft.WindowsAzure.ServiceRuntime Stack Trace: at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable() at Microsoft.ApplicationServer.Caching.AzureClientHelper.RoleUtility.IsAzureEnvironmentAvailable() Stack Trace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object […]