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:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,227
Location
Virginia Beach, VA
Programming Experience
10+
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?
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
There's no AV running.
I've tried solve the problem by turning the WIndows firewall totally off. But the problem still occurs.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,227
Location
Virginia Beach, VA
Programming Experience
10+
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.
 

Sheepings

Senior Programmer
Staff member
Joined
Sep 5, 2018
Messages
1,141
Location
UK
Programming Experience
10+
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
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
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 :-(
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
Trying another port has no result.
I've added BitViseApi to the allowed apps (in settings of Windows FireWall). Also no result.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,227
Location
Virginia Beach, VA
Programming Experience
10+
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?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,227
Location
Virginia Beach, VA
Programming Experience
10+
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.
 

Sheepings

Senior Programmer
Staff member
Joined
Sep 5, 2018
Messages
1,141
Location
UK
Programming Experience
10+
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.
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
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
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
(perhaps unnecessarily, but the 'api server' and the listening client are in this case on the same machine)
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
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?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,227
Location
Virginia Beach, VA
Programming Experience
10+
I really suggest talking to your IT Security staff to see what is happening. I would have expected your application to be listening directly to the port -- not having the system proxying to your application. If you run the same code on your personal machine that is not managed by your IT staff does it also show system as listening?
 

CorBins

Member
Joined
May 12, 2020
Messages
11
Location
The Netherlands
Programming Experience
10+
Hi Skydiver,
Yes, indeed, it shows on my local machine system as listening.
And this doesn't cause any problem; de api returns the right answers:unsure:.
 

Sheepings

Senior Programmer
Staff member
Joined
Sep 5, 2018
Messages
1,141
Location
UK
Programming Experience
10+
That's not what he asked you. He asked you if the 'system' is listening on your local machine to the same ports?

If your API works locally. You need to contact your server provider, and have them trace the problem for you. Until you can prove that there is an issue with C# or your programming, there is currently little we can help you with until they get back to you.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,227
Location
Virginia Beach, VA
Programming Experience
10+
There was a point in the history of .NET Core when they switched over to default to HTTPS. They figured out that devs are lazy and won't take the extra steps to go to HTTPS to make their apps more secure so they decided that secure by default should be encouraged.

Now the question is: why did it work for you and your friend, but not on the server? Or was this pilot error? On the local machines, the pilots automatically decided to use HTTP knowing that no certificates were installed, and then used HTTPS when talking to the server presuming that a certificate would be present?
 
Top Bottom