【问题标题】:Azure WebJob access deniedAzure WebJob 访问被拒绝
【发布时间】:2017-03-01 11:25:31
【问题描述】:

所以我在本地创建服务时遇到问题,我的应用程序作为 WebJob。好像我阅读了所有谷歌,但我找不到解决方案。 This one here 对我来说不算数,因为它是关于身份验证的。

所以,我的电脑上有一个 C# 控制台应用程序,其中包含许多引用、ddls 和大量计算,它们像服务一样运行。主函数,如下所示:

    static void Main(string[] args)
    {
        string baseAddress = "http://127.0.0.1:80";
        Console.WriteLine(baseAddress);
        if (args.Count() > 0 && !string.IsNullOrEmpty(args[0]))
            baseAddress = args[0];
        SelfHostServer server = new SelfHostServer();            //using Microsoft.Owin;
        server.Start(baseAddress);
    }

然后我在 Azure AppService 上发布了一个 nodeJs 应用程序。基本上,我需要它来调用 C# 服务并获得结果响应。出于这个原因,我试图用我的 C# 应用程序创建一个 WebJob。我发布它并尝试运行它,但我得到(这个错误是来自天蓝色的门户控制台):

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.HttpListenerException: Access is denied
   at System.Net.HttpListener.SetupV2Config()
   at System.Net.HttpListener.Start()
   at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener, Func`2 appFunc, IList`1 addresses, IDictionary`2 capabilities, Func`2 loggerFactory)
   at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app, IDictionary`2 properties)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(StartContext context)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
   at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
   at Avilda.Klevas.Core.Server.SelfHostServer.Start(String baseAddress)
   at klevas.webapistart.Program.Main(String[] args)

看来是端口的问题,但我无论如何都找不到合适的。我可以运行其他 exe,但不能运行听者的。我不在乎 C# 应用程序是否无法从外部访问,我只希望这两个能够通信。有任何想法吗?或者其他解决方案(VM除外)?

【问题讨论】:

  • 我现在设法在我的计算机上本地获取此错误。然后通过以管理员身份运行 Visual Studio 来解决它。所以 idk,也许有办法以管理员身份运行 WebJob?

标签: c# node.js azure port azure-webjobs


【解决方案1】:

如下文所述每个应用程序都看到一个“私有”环回连接;应用“A”无法监听应用“B”建立的本地环回套接字。

Operating system functionality on Azure App Service

由于不允许监听端口,我建议你改为监听队列存储。任何想要向您的 WebJobs 发送消息的应用程序都可以将消息插入到队列存储中。 WebJobs SDK 为您提供了一种简单的方法。下面的代码供您参考。如果消息已插入 queue1,将触发以下方法。

public static void ProcessQueueMessage([QueueTrigger("queue1")] string logMessage, TextWriter logger)
{
    logger.WriteLine(logMessage);
}

如果您想将消息从 WebJobs 发送回节点应用程序,还请在您的节点应用程序中侦听队列并将消息插入到队列中。

【讨论】:

  • 搞了半天,回来解决这个问题。存储队列对我来说非常有用。其他人做类似事情的另一种选择(不需要端口监听或队列): 1. 重新制作 exe 以通过 cmd 行获取参数 2. 从节点运行 exe 并使用您需要的参数:2.1 var exec = require('child_process')。执行; 2.2 ( exec('test.exe {parameters}', ['/C'], function(err, cmdOut, stderr) { )
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 2017-05-17
  • 2015-11-23
相关资源
最近更新 更多