2017-02-24 170 views
2

所以我創建一個服務localy,爲我的應用程序作爲WebJob有問題。這看起來像我閱讀所有的谷歌,但我找不到解決方案。 This one here不包括我,因爲它是關於驗證。Azure WebJob訪問被拒絕

因此,我有一個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); 
    } 

然後我有一個nodeJs應用程序發佈在Azure AppService上。基本上,我需要它調用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) 

它看起來像它與端口有問題,但我找不到任何合適的人anywere。我能夠運行其他exe文件,但不能與誰在監聽。我不在乎C#應用程序是不是可以從外部訪問,我只是想讓這兩個人進行交流。有任何想法嗎?或者也許其他解決方案(虛擬機除外)?

+0

我設法在我的電腦上本地獲取此錯誤。然後通過以管理員身份運行Visual Studio來解決此問題。所以idk,也許有辦法以管理員身份運行WebJob? – Shpooke

回答

2

以下文件記錄爲每個應用程序都看到一個「專用」回送連接;應用程序「A」無法收聽由應用程序「B」建立的本地環回套接字。

Operating system functionality on Azure App Service

由於監聽的端口是不允許的,我建議你聽隊列存儲來代替。任何想要將消息發送到WebJobs的應用程序都可以向隊列存儲插入消息。 WebJobs SDK爲您提供了一個簡單的方法。以下代碼供您參考。如果消息已插入隊列1,則將觸發以下方法。

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

也請聽隊列中的節點的應用程序,如果你想從你的WebJobs消息發送回節點的應用程序插入一個消息隊列。

+0

很久以後,我回來解決這個問題。儲存停用對我來說非常合適。爲別人做類似的東西 還有一個選項(無端口監聽或quenue需要): \t 1.重拍EXE通過CMD線得到的參數 \t 2.從節點運行的exe與參數,你需要: \t \t 2.1 VAR EXEC = require('child_process')。exec; (exec('test.exe {parameters}',['/ C'],function(err,cmdOut,stderr){) – Shpooke