问题
I'm just getting into WCF programming. I've set up a self-hosted test web service on my work computer, which is behind a firewall; it's at http://localhost:8000/MyTestService
. I can access the service page through the browser; all working fine.
Now I want to access that service from my home computer, which is on a different network. I have a dynamic dns (call it mydomain.dyndns.org) set up to point to my work router. Have tested, dyndns is pointing to the right address.
Now I have installed a test app on my home computer to connect to my web service. So I configured my NAT for forward requests on port 8000 to my work computer, on the same port number.
On my home computer I now open a browser and navigate to http://mydomain.dyndns.org:8000/MyTestService
. Nothing doing.
Obviously I'm missing something really fundamental about NATs and port forwarding... but as I say, I'm kinda new at this aspect of programming, and I'd really appreciate some guidance here!
回答1:
Do you see an error or an empty page? Can you check canyouseeme.org from the computer behind the firewall that the port is really open? Can you check with tools like sysinternals tcpview that the connection attempt reaches this computer and not just the router?
回答2:
I had the same problem.
after a good help from this toppic. http://www.codeproject.com/Questions/140317/WCF-services-and-Windows-Firewall. My WCF Service worked well on the local LAN even with the firewall active.
But it was not accessible over the internet. After port forwarding i could see the service description. but I couldn't use it.
This article http://gavinmckay.wordpress.com/2009/03/24/howto-fix-wcf-host-name-on-iis/ points me in the right direction. The service is visible, but connections to your web server will fail because the WSDL is pointing to the non-published server name and your client won’t be able to get there.
In my case a I need to change the self hosted wcf the local endpoint to the public one.
// 1 Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://publicdomain.com:8000/GettingStarted/");
// Step 2 Create a ServiceHost instance
ServiceHost selfHostRemote = new ServiceHost(typeof(MyService), baseAddress);
来源:https://stackoverflow.com/questions/4525901/wcf-service-behind-firewall-how-to-set-up-port-forwarding