WCF Web Service本地运行正常,指定IP访问失败求助
Hey there! I’ve dealt with this exact WCF access issue a few times before, so let’s walk through the most likely fixes to get your service working on 192.168.1.103:80:
Fix your WCF binding configuration
Double-check yourweb.configorapp.config—the service might be hardlocked tolocalhost. Look for the<system.serviceModel>section:- For your endpoint, use a wildcard (
*) or the specific IP instead oflocalhostin the address, like:<endpoint address="http://*:80/YourService" binding="basicHttpBinding" contract="IYourServiceContract" /> - Add or ensure the
<serviceHostingEnvironment>node hasmultipleSiteBindingsEnabled="true"to support multiple address bindings:<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
- For your endpoint, use a wildcard (
Grant port listening permissions
Port 80 is a privileged port, so your service process might not have permission to listen on it.- Open Command Prompt as Administrator.
- Run
netsh http show urlaclto check ifhttp://192.168.1.103:80/has an entry. - If not, add the permission with:
netsh http add urlacl url=http://192.168.1.103:80/ user=YourWindowsUsername
Replace
YourWindowsUsernamewith your actual login account for better security than usingEveryone.Adjust firewall settings
Your local firewall is probably blocking incoming traffic on port 80:- Open Windows Defender Firewall > Advanced Settings > Inbound Rules.
- Create a new rule to allow TCP traffic on port 80, targeting either your WCF service executable or all programs.
- If you’re accessing from another device on the network, make sure your router firewall isn’t blocking port 80 either.
Verify your machine’s IP and network adapter
- Run
ipconfigin Command Prompt to confirm your machine is actually using192.168.1.103(sometimes IPs change if DHCP is enabled). - If you have multiple network adapters (wired + wireless), ensure the service is binding to the correct one—using
*in the endpoint address will bind to all adapters, which is usually safer.
- Run
Test locally first
- Try accessing
http://192.168.1.103:80from the same machine running the service. If this fails, the issue is local (config/permissions). If it works, the problem is with network connectivity between devices. - Use
Test-NetConnection 192.168.1.103 -Port 80in PowerShell to quickly check if the port is reachable.
- Try accessing
Check hosting setup
- If self-hosting: Make sure your service startup code explicitly binds to the IP/port, not just
localhost. Example:var serviceHost = new ServiceHost(typeof(YourService)); var binding = new BasicHttpBinding(); serviceHost.AddServiceEndpoint(typeof(IYourServiceContract), binding, "http://192.168.1.103:80/YourService"); serviceHost.Open(); - If IIS-hosted: Go to your website’s Bindings in IIS Manager, and add a new binding for
192.168.1.103on port 80—don’t just rely on thelocalhost:55077binding.
- If self-hosting: Make sure your service startup code explicitly binds to the IP/port, not just
Give these steps a shot, and let me know if you hit any snags!
内容的提问来源于stack exchange,提问作者Sevket

