我使用 WSHttpBinding 创建了 WCF 服务:
ServiceHost svh = new ServiceHost(typeof(MyService));
var httpLocation = "http://" + address + ":4041";
svh.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding(SecurityMode.None), httpLocation);
svh.Open();
我已经在系统中注册了
netsh http add urlacl url=http://+:4041/ user=username
当我尝试从 localhost 连接到它时,该服务可以正常工作。
但是当我把它放在另一台电脑上时(地址='localhost'或地址='ip-of-the-machine'),连接失败,出现以下异常:
There was no endpoint listening at http://192.168.44.128:4041/ that could accept
the message. This is often caused by an incorrect address or SOAP action. See
InnerException, if present, for more details.
内部异常:
A connection attempt failed because the connected party did not properly respond
after a period of time, or established connection failed because connected host
has failed to respond 192.168.44.128:4041
我尝试将服务添加到防火墙,但没有帮助。
这里有什么问题?
更新
以下是来自 的相关条目netstat -ano
。第一个是 http 端点,不能从外部连接,第二个是 net.tcp 端点,可以正常工作:
TCP [::]:4041 [::]:0 LISTENING 4
TCP 192.168.44.128:9939 0.0.0.0:0 LISTENING 2120