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:
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?
 
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.
 
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?
 
Back
Top Bottom