Search code examples
network-programmingself-host-webapi

How to expose .NET self hosted Web API over the Internet


I have a WPF application running on a laptop that is self hosting a Web API on Port 9001 for that laptop's network IP address. I am able to successfully send Http traffic to that port from different machines on my local home network.

I need to run tests from a remote location over the Internet to this same laptop. I have done the following:

  • Created a static IP address for my laptop
  • Added an inbound rule in the firewall to allow TCP for port 9001 for any incoming domains or IP's
  • Added TCP Port forwarding in my Verizon router for port 9001 to that laptop's IP address
  • Went to CanYouSeeMe.org and confirmed that my ISP is not blocking that port on my External, Internet facing IP address
  • To test this from my local network I sent an Http request via Fiddler to my External IP Address and that Port and the API successfully executed
  • I also can successfully access that API from any computer on my network using the External IP and port.

However, if I try to access that same External Address and Port from a computer that is NOT on my network it returns an http 502 status that the connection failed. Any ideas where I should be looking next?

Thanks, Jim


Solution

  • As it turns out this was working all along and the steps I went through above are correct.

    In order to test this to ensure it worked outside of my network I had to use an offsite server that I have access to via RDP. That server is also the one that ultimately will be hitting my laptop for testing. After going down some false paths, it seems that the server, which I don't have permission to configure, most likely needs an outbound rule for the port I'm using.

    Every other method of access off my network is working such as cellphone access and remote testing from others. Should have done that first. I guess I just spent too much time asking myself what I was missing. Hopefully someone can benefit from the steps above.