1

I try to create an asp.net service; which works if I try to access it locally. But it is not possible to reach it from a remote location.

Below the code I use to instantiate the server:

using System;
using System.Web.Http;
using System.Web.Http.SelfHost;
using System.Configuration;

namespace RESTService
{
  public class Service : IDisposable
  {
    private HttpSelfHostServer server;

    public Service()
    {
      var config = new HttpSelfHostConfiguration($"http://*:{ConfigurationSettings.AppSettings["port"]}/");
      config.Routes.MapHttpRoute("TTS", "{controller}/{text}",
        new[] { "RESTService.Controller" });

      server = new HttpSelfHostServer(config);
    }

    public void Run()
    {
      server.OpenAsync().Wait();
    }

    public void Dispose()
    {
      server.Dispose();
    }
  }
}

I replaced localhost with * as described in Web API self host - bind on all network interfaces. Unfortunately I get an UriFormatException with this code. How can I bind the service to all interfaces?

Patrik Gfeller
  • 1,095
  • 9
  • 16

1 Answers1

0

Thanks to Lex Li; his comment pointed me into the right direction. The following code works:

new HttpSelfHostConfiguration($"http://{IPAddress.Any}:{ConfigurationSettings.AppSettings["port"]}/")
Patrik Gfeller
  • 1,095
  • 9
  • 16