Application with API not working on server

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
With Visual Studio, I created a console application with api (8 apiControllers). On my local machine, it works fine. On the machine of my colleague also no problem. When copying the exe-file to a WindowsServer2012R2, there's a problem. The api listens to port 44311. The exe is running. When looking with netstat, I see port 44311 is listening. But, when trying to get some answer in a browser, nothing appears (in the browser, I've to enter the url https://localhost:44311/BitVise/Test). The API has a swagger, but in the browser, the swagger also returns nothing but the error 'this site is not available'.

Some code: Program.cs:
C#:
using System;
using System.Configuration;

namespace BitViseApi
{
  class Program
  {
    static void Main(string[] args)
    {
      string domainAddress = ConfigurationManager.AppSettings["domainAddress"];
      using (WebApp.Start(url: domainAddress))
      {
        Console.WriteLine("Service Hosted " + domainAddress);
        System.Threading.Thread.Sleep(-1);
      }
    }
  }
}
Startup.cs:
C#:
using Owin;
using System.Web.Http;

namespace BitViseApi
{
    class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.EnableCors();
            config.Routes.MapHttpRoute(
                name: "createUserApi",
                routeTemplate: "Bitvise/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
            SwaggerConfig.Register(config);
            appBuilder.UseWebApi(config);
        }
    }
}

Beginning of BitViseController.cs:
C#:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.Cors;
using BssCfg815Lib;
using System.Security.Cryptography;
using System.Text;
using NLog;

namespace BitVise
{
   [EnableCors(origins: "*", headers: "*", methods: "*")]

    public class TestController : ApiController
    {
        public string Get()
        {
            return "BitViseAppi is working";
        }
    } // TestController

    public class VirtAccountsController : ApiController
    {
        public IEnumerable<LocalVirtAccount815> Get(string username, string password)
        {
            string result;
            BitViseHelper helper = new BitViseHelper();
            helper.Log(LogLevel.Info, "Call to VirtAccounts. Login: username=" + username + ", password=" + password);
            bool loginOkay = helper.CheckUser(username, password, out result);
            if (!loginOkay)
            {
                helper.Log(LogLevel.Error, "  Login failed: " + result);
                return null;
            }
            helper.Log(LogLevel.Info, "  Login succeeded.");
            List<LocalVirtAccount815> virtAccounts = helper.ListVirtAccounts();
            helper.Log(LogLevel.Info, "  " + virtAccounts.Count + " Virtual accounts retrieved.");
            return virtAccounts;
        }
    } // VirtAccountsController


...
Image showing the console app is running, listening and the browser showing the error.
BitVise.png


Does anyone have an idea what I have forgotten or what I am doing wrong?

Thanks in advance,

Cor
 
Last edited:
What AV is running on that server? Is there a firewall setting? Have you tried disabling the AV or poking a hole in the firewall for that port?
 
As I recall, netstat can tell you which process is listening. Is it actually your app? Or is there another Kestrel based app that has already grabbed the port before you could?

Also are you absolutely sure there is no AV or other software which may actually like a firewall like some nannyware? This past two weeks, my company has been hit hard with entire populations of PCs either unable to accept the corporate VPN, and the Internet. When we first asked the end point security team if they had changed anything, they said no. We started asking others if they had deployed any AV software. Still no. It turned out that a different security team attached to the legal department had deployed a "data loss prevention" application that is technically not an AV -- it was just nannyware.
 
That doesn't tell us what application is using the port. So I think its safe to assume something else is probably running on the port if you can't access it. Double check all firewall rules.

Use this in Elevated CMD : tasklist | findstr YOUR EXECUTABLE NAME
Or better : netstat -ano | findStr 44311 - This gives you the pid running on the port. Then run :
tasklist /FI "PID eq pidhere" Obviously you replace pidhere with the actual pid from the first command.

And post the output here. You should have something like this example :

Screenshot_138.jpg
 
Excuse me.
The PID of the BitViseApi is 2608.
And the PID of the process listening to port 44311 seems to be 4.
So, it's clear my application BitViseApi isn't listening to port 44311 :-(
 
When you changed port numbers, did netstat also report that port as listening as well? If so, which app was listening on that port? Also system?
 
It sounds like there some AV or nannyware that is running and sitting in front of your application proxying the ports that you trying to open -- and that bit of AV or nannyware is not running on your local machine, but is running on the server. I suggest contacting your server admins and/or security team to see what they have to say.
 
By any chance, are you running any applications like PeerBlock?

If your API works on TCP, then download and run this : TCPView for Windows - Windows Sysinternals

Then tell us what the service is that runs on your port when your application starts. Once we know that much, we should be able to disable it.

That program will also allow you to kill the service. Although, so as not to break something, just report back what service is it first.
 
Thanks for your reply.
I've contacted my team, but they're sure no AV is running. Maybe its nannyware.

After installing TCPView, no process is listening to port 44311.
Starting my api, process with pid 4 (system) is listening.
BitVise3.jpg
 
Just, I tried to run the application on my local machine. With the same result! Also system (pid=4) is listening to the port 44311.
But: sending a request to my api, I get the right result!
So, the fact system is listening to 'my port' should not be the problem.

So, there's another reason the api is not responding.
Anybody any idea?
 
Back
Top Bottom