【问题标题】:Can't access a Console hosted WCF service from a remote client on LAN无法从 LAN 上的远程客户端访问控制台托管的 WCF 服务
【发布时间】:2014-06-26 07:51:10
【问题描述】:

现在有几天,我试图从局域网上的另一台计算机访问我的 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 服务标识自己”

然后我尝试将安全性设置为无(出于故障排除目的),但我只得到了一个超时异常

编辑 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

【问题讨论】:

  • 可能是因为防火墙阻塞了 3100 端口。
  • 您是否在 IIS 上托管 WCF 服务?
  • @daryal 防火墙关闭,问题出在 ;)
  • @Ksven 不,我正在使用控制台应用程序托管服务
  • 从客户端telnet到主机的3100端口,看看是否真的可达:)

标签: c# wcf networking .net-4.5


【解决方案1】:

这是您的问题的解决方案。

客户的应用配置

<?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 端口共享服务(在服务器端和客户端)才能使其正常工作。

【讨论】:

  • 感谢您的回答,我会试试的,知道为什么wsDualHttpBinding 不起作用吗?我真的需要将安全模式设置为无吗?还是只是为了调试目的才放在这里?
  • 我建议通过 wsHttpBinding 的示例来了解它的基础知识 (msdn.microsoft.com/en-us/library/ff648431.aspx)。为方便起见,我已将安全模式设置为“无”。你可以在这里阅读更多内容msdn.microsoft.com/en-us/library/ms731316(v=vs.110).aspx
  • 客户端不需要启用Net.tcp端口共享,我只是用两个远程客户端和一个本地客户端进行了测试。一切正常,不过我只在服务器上启用了 Net.Tcp 端口共享。无论如何,感谢您的帮助。
  • 感谢信息...我在我身边的那个端口上运行了另一个应用程序...yw
  • 我可以确认这一点,我尝试在其中一个远程客户端上启动第二个实例,但在我尝试连接时它崩溃了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-26
  • 1970-01-01
相关资源
最近更新 更多