9

I'm trying to self host an OWIN pipeline in a WinForms application. The pipeline is hosting up both static files and Web Api v2 content. The implementation is working great locally, but I'm not sure what I'm missing in order to be able to access the hosted files and APIs from remote machines on my network.

For simplicity sake, I downloaded the sample self-host app from codeplex here and tried accessing the test methods remotely after making the below modifications to the base address (I tried both running the netsh regisration and I'm running in Admin mode) and I still can't access them. What do I need to change in the configuration to be able to view the content from other computers on the same network?

static void Main()
{
    string baseAddress = "http://*:10281/";
    // Start OWIN host
    using (WebApp.Start<Startup>(url: baseAddress))
    {
        // Create HttpCient and make a request to api/values
        HttpClient client = new HttpClient();

        HttpResponseMessage response = client.GetAsync("http://localhost:10281/api/values").Result;

        Console.WriteLine(response);
        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
        Console.ReadLine(); // Keeps the host from disposing immediately
    }
}

Here's the Startup Configuration, pretty basic stuff:

public class Startup
{
     // This code configures Web API contained in the class Startup, which is additionally specified as the type parameter in WebApplication.Start
    public void Configuration(IAppBuilder appBuilder)
    {
        // Configure Web API for Self-Host
        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        appBuilder.UseWebApi(config);
    }
}
Duck Jones
  • 380
  • 1
  • 5
  • 16
  • `client.GetAsync("http://localhost:10281/api/values")` probably want to change "localhost" to the IP address of your machine to see that end point remotely... Or use the same base address format, although I think you should be using "+" instead of "*" if I remember right. – Ron Beyer Jul 20 '15 at 15:40
  • That's just the test code, I use my IP address when testing in both local browsers and on the remote machines. – Duck Jones Jul 20 '15 at 15:42

1 Answers1

9

That code looks fine and there's no reason it shouldn't work, especially if you can access the OWIN server locally.

There's two likely issues preventing network access. Either you need to add an Inbound Rule to Windows firewall for port 10281 (or temporarily disable any firewalls on the hosting computer), or your network is blocking the traffic somehow.

Zephyr
  • 791
  • 5
  • 9
  • Windows Firewall got me. Should have known, I've always been prompted before when firing up a new application that needed firewall access. Not sure what's so different about an OWIN application, but Windows never asked me. I added the Inbound Rule and voila! – Duck Jones Jul 20 '15 at 17:54