10

Very new to the Self Host WebApi, but I am very impressed with its ease of use and extendability. At least through this tutorial. Everything I've done so far works on my development machine whether I use localhost, 127.0.0.1, or my LAN Ip (192.168.0.x) but I am baffled why I can't access the service from any other computer even others in the same subnet.

In short after going through the tutorial on the machine where it is running: Browsing to

localhost:3636/api/products/ 

results in the expected xml return. On another machine on the LAN browsing to:

192.168.0.x:3636/api/products/ 

results in a timeout Data points for those who might know how this all interacts:

1.) My dev machine(192.168.0.x, server, host whatever you want to call it) has IIS on it; I was so paranoid it was in the way that I stopped it via the Administration GUI

2.) I have reserved the URL/Port with the following command line executions:

    >netsh http add urlacl url=http://+:3636/ user=DOMAIN\USER listen=yes delegate=yes
    >netsh http add urlacl url=http://192.168.0.x:3636/ user=DOMAIN\USER listen=yes delegate=yes

2.b) I've tried both of those together and individually, and tried changing the user to "everyone" to no avail

3.) I have tried to change the code in the tutorial to set the

    config.HostNameComparisonMode = HostNameComparisonMode.Exact //default is Strong Wildcard 

4.) I can successfully ping and tracert to 192.168.0.x from other machines on the LAN

5.) A friend recommended I setup a TCPListener and ensure I could telnet to that to eliminate the firewall as a possibility. If that logic is sound, the firewall isn't the problem

EDIT: Thanks for your help, here's another data point that I believe confirms it's not a firewall issue. I previously posted this connection when behind a rather obtuse (at least to a non Certified guy like me) Juniper Firewall/Router. I have since redone the tutorial on another machine (without IIS) on my home network and still cannot publish the service to other computers within my LAN. Any ideas?

whytheq
  • 34,466
  • 65
  • 172
  • 267
David
  • 437
  • 4
  • 12
  • Are you running the service under DOMAIN\USER? I usually find that its easier to run the service as NETWORK SERVICE and then in the netsh command you put user="NT AUTHORITY\NETWORK SERVICE" – Darrel Miller Jun 01 '13 at 02:09
  • Also, I would double check your firewall and make sure netstat -a shows your service listening. – Darrel Miller Jun 01 '13 at 02:11
  • Thank you Darrel for the ideas. I'm currently still running the service in debug under my User (who has admin rights if that matters). I ran netstat -a (on my dev/hosting machine if that's what you meant) and see the following entries (among others): Proto Local Address Foreign Address State TCP 0.0.0.0:3636 DOMAIN:0 LISTENING TCP [::]:3636 DOMAIN:0 LISTENING Not quite sure what to make of that. I guess I will try to confirm the firewall. – David Jun 01 '13 at 13:02

3 Answers3

3

Well it wasn't the hardware firewall, it was the windows firewall! yikes i wasted a bunch of time on that. Once I turned off the windows firewall (the code runs in an intranet anyway) everything worked.

Anyone know of a good site that explains how firewalls and wireshark interact; or i suppose that just has to be one's first test.

David
  • 437
  • 4
  • 12
0

I would try a couple things:

First off, get rid of the HostNameComparisonMode line. That might actually disable requests coming from other machines.

If things still don't work, try getting rid of the URL ACLs and run your application as an administrator and see if that works. If that works, you may be able to add the URL ACL back on and not have to run as an administrator. You should only need the one with '+' as the hostname.

Youssef Moussaoui
  • 12,187
  • 2
  • 41
  • 37
  • From my experience, if IIS is running on the same machine then you need HostNameComparisonMode.Exact or IIS will steal the requests. Hmm, wait, maybe not on a port other than 80. – Darrel Miller Jun 01 '13 at 02:05
  • I apologize I forgot to mention everytime I've tried to change HostNameComparisonMode I've gotten an exception at the server.OpenAsync().Wait(); line. The exact exception is nested(multiple levels of inner) as: System.AggregateException/System.ServiceModel.CommunicationException/.Net.HttpListenerException: "The format of the specified network name is invalid". That's why I thought that wouldn't work – David Jun 01 '13 at 12:42
  • I got it to compile and run changing my config contruction parameter from 196.168.0.x to localhost; however then the service failed to work on the local machine so that's out. – David Jun 01 '13 at 12:55
  • Change the config to localhost and don't set the HostNameComparisonMode. That should work both for local machines and remote machines. – Youssef Moussaoui Jun 01 '13 at 13:16
  • Thank you Youssef for your time but i don't see any change in behavior. I've rebooted and the ACLs were gone before I started my selfhost and apparently acquired the ACL by itself; however no other change. – David Jun 01 '13 at 13:42
0

I faced the same problem when i tried to self host using OWIN. What worked for me was -

  1. Run Visual Studio as an Admin
  2. Remove any and all netsh urlacl port registrations that I had added while debugging this issue
  3. Add a inbound rule to my windows firewall I followed the instructions on this link https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/firewall-instructions Check out the section - To enable a port range in advance

That's it! I was able to call my api from other computers on the network.

Hope this helps...

karthiks3000
  • 842
  • 8
  • 12