title: Is it possible to run a self hosting OWIN web api inside WinForms (C#)?
body: <p>I am trying to migrate my self-hosting OWIN WebApiService from a Windows Service app to WinForms. Here's my Startup.cs code:</p>
  
  <pre><code>public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          // Configure the db context and user manager to use a single instance per request
          var oAuthServerOptions = new OAuthAuthorizationServerOptions()
          {
              AllowInsecureHttp = true,
              TokenEndpointPath = new PathString("/auth/token"),
              AccessTokenExpireTimeSpan = TimeSpan.FromDays(31),
              //owin providers go here, doesn't matter
          };
  
          // Token Generation
          app.UseOAuthAuthorizationServer(oAuthServerOptions);
          app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
  
          app.UseWebApi(ConfigureWebApi());
      }
  
      private HttpConfiguration ConfigureWebApi()
      {
          var config = new HttpConfiguration();
  
          var jsonFormatter = config.Formatters.JsonFormatter;
          jsonFormatter.SerializerSettings.Formatting = Formatting.None;
          jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
          jsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
          config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
  
          config.Routes.MapHttpRoute(
              "DefaultApi",
              "api/{controller}/{id}",
              new { id = RouteParameter.Optional });
  
          return config;
      }
  </code></pre>
  
  <p>Then, the web service :</p>
  
  <pre><code>public static class WebService
      {
          static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  
      public static void Run()
      {
          log4net.Config.XmlConfigurator.Configure();
          var _ip = "localhost";
          var _port = "1532";
          var url = _ip + ':' + _port;
  
          try
          {
              WebApp.Start&lt;Startup&gt;(url);
          }
          catch (Exception ex)
          {
              log.ErrorFormat("Error on starting web service. Exception : {0}.", ex.Message);
              return;
          }
          log.Info("Service has been started.");
      }
  
  }
  </code></pre>
  
  <p>As a windows service, it's all going fine and all is working. But when I'm trying to run the web service from Winforms app (both from Program.cs or from my form code) - it's looking OK, but I cannot connect to the service nether via  HTTP clients (Chrome, Postman etc.), not via my HTTP client code. </p>
  
  <p>Is is possible to host Web Api in Winforms? Anyone Can help?</p>
  
  <p>P.S. Firewall is turned off. Port also doesn't matter, I tried at least five.</p>