2

so I have a problem creating a service localy, for my app as a WebJob. It seems like I read all google, but I can't find the solution. This one here doesn't count for me, because it is about authentification.

So, I have a C# console application on my pc with MANY references, ddls and lots of calculations which runs like a service. Main function, looks like this:

    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);
    }

Then I have a nodeJs application published on Azure AppService. Basicaly, I need it to call C# service and get a response with result. For this reason I am trying to create a WebJob with my C# app. I publish it and try to run it, but I get(this error is flom azure portal console) :

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)

It looks like it's a problem with port, but I can't find any right one anywere. I am able to run other exe's, but not the one's with who listens. I do not care if C# app will not be reachable from the outside, I just want those two to communicate. Any ideas? Or maybe other solutions(except VM)?

Community
  • 1
  • 1
Shpooke
  • 60
  • 1
  • 6
  • I managed to get this error locally on my computer now. And then solved it by runing Visual studio as administrator. So idk, maybe there is a way to run WebJob as Administrator? – Shpooke Feb 24 '17 at 14:57

1 Answers1

2

As following document noted each app sees a "private" loopback connection; app "A" cannot listen to a local loopback socket established by app "B".

Operating system functionality on Azure App Service

Since listen to the port is not allowed, I suggest you listen to queue storage instead. Any apps who want to send message to your WebJobs could insert a message to the queue storage. WebJobs SDK provide an easy way for you to do it. Code below is for your reference. Following method will be trigged if a message has been inserted into queue1.

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

Please also listen to a queue in your node app and insert a message to the queue if you want to send a message back from your WebJobs to the node app.

Amor
  • 8,325
  • 2
  • 19
  • 21
  • After a long time, i came back to solve this problem. Storage quenue worked perfectly for me. One more option for others doing something like that(no port listening or quenue needed): 1. Remake exe to get parameters via cmd line 2. Run exe from node with parameters you need: 2.1 var exec = require('child_process').exec; 2.2 ( exec( 'test.exe {parameters}', ['/C'], function(err, cmdOut, stderr) { ) – Shpooke Sep 18 '17 at 13:41