[英]Can't access a Console hosted WCF service from a remote client on LAN
几天以来,我一直在尝试从LAN上的另一台计算机访问WCF服务,但无法访问它。
在本地,虽然工作正常。
我可以找到的大多数类似问题都是使用IIS托管服务。
我试图关闭防火墙,但没有任何效果。
这是配置文件,请询问您是否需要更多:
客户端的App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<client>
<endpoint name="default"
address="http://myhostIP:3100/"
binding="basicHttpBinding"
contract="ServiceInterface.IService"/>
</client>
</system.serviceModel>
</configuration>
这是主机App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<services>
<service name="ServiceTest.Service">
<endpoint address="http://0.0.0.0:3100"
contract="ServiceInterface.IService"
binding="basicHttpBinding"/>
</service>
</services>
</system.serviceModel>
</configuration>
如果你们有什么主意...我找不到任何信息
编辑:
我正在使用控制台应用程序托管服务
来自本地和远程主机的Telnet连接正常
编辑2:
我只是看到复制App.config文件时出错。 绑定类型应该是wsDualHttpBinding
而不是basicHttpBinding
我也会收到错误消息:
第一个是“呼叫者无法向WCF服务标识自己”
然后,我尝试将安全性设置为none(出于故障排除的目的),并且我只有一个超时异常
编辑3:
在控制台应用程序中:
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(ServiceTest.Service));
host.Open();
Console.WriteLine("Server Started");
Console.ReadLine();
}
编辑4:
完整的解决方案可在这里https://github.com/sidewinder94/smallChatSolution
这是您的问题的解决方案。
客户端的应用程序配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<client>
<endpoint name="default"
contract="ChatDllContracts.IService"
binding="netTcpBinding"
address="net.tcp://myHostIp:3100/"
bindingConfiguration="mynet"/>
</client>
<bindings>
<netTcpBinding>
<binding name="mynet" sendTimeout="00:00:05" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
ChatServer的app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<system.serviceModel>
<services>
<service name="ChatDll.Service">
<endpoint contract="ChatDllContracts.IService"
binding="netTcpBinding"
address="net.tcp://localhost:3100"
bindingConfiguration="mynet"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="mynet" sendTimeout="00:00:05" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
请记住,您需要启用Net.Tcp端口共享服务 (在服务器和客户端),以使其正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.