C# 无法连接到 net.tcp:连接尝试持续了一段时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13982857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not connect to net.tcp: The connection attempt lasted for a time span
提问by dotnet-practitioner
On remote build machine, I get the following error when I run my unit test.
在远程构建机器上,运行单元测试时出现以下错误。
Test method MyNameSpace1.MyNameSpace2.Service.Test.MyPath.XYZServiceTest.FindRecord threw exception: System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://localhost/MyABCServices/XYZService.svc. The connection attempt lasted for a time span of 00:00:02.0086605. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:808. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:808
测试方法 MyNameSpace1.MyNameSpace2.Service.Test.MyPath.XYZServiceTest.FindRecord 抛出异常:System.ServiceModel.EndpointNotFoundException:无法连接到 net.tcp://localhost/MyABCServices/XYZService.svc。连接尝试持续了 00:00:02.0086605 的时间跨度。TCP 错误代码 10061:无法建立连接,因为目标机器主动拒绝它 127.0.0.1:808。---> System.Net.Sockets.SocketException: 无法建立连接,因为目标机器主动拒绝它 127.0.0.1:808
I have very limited access to this build machine. I do not have access to iis on build machine or the services like I do on my local dev machine. The unit tests work on my local dev machine but they run in to error mentioned above on build machine.
我对这台构建机器的访问非常有限。我无法像在本地开发机器上那样访问构建机器上的 iis 或服务。单元测试在我的本地开发机器上工作,但它们在构建机器上遇到了上面提到的错误。
What can I do to debug this error? I have read things like check the fire wall etc. But I do not know how to do that? I can not check if the windows service for this service is up and running on the build machine. I tried to log into the build machine or connect my IIS to this remote machine but I could not.
我能做些什么来调试这个错误?我已经阅读了诸如检查防火墙等内容。但我不知道该怎么做?我无法检查此服务的 Windows 服务是否已在构建机器上启动并运行。我试图登录到构建机器或将我的 IIS 连接到这台远程机器,但我不能。
采纳答案by Erik Noren
The most common problem for me is the Windows Service Net.Tcp Listener Adapter is not running on the hosting machine.
对我来说最常见的问题是 Windows Service Net.Tcp Listener Adapter 没有在主机上运行。
Also check your IIS Web Application to ensure Enabled Protocols includes net.tcp. For instance mine has "http,net.tcp" and in my bindings I have "http::94:,net.tcp:194:"
还要检查您的 IIS Web 应用程序以确保启用的协议包括 net.tcp。例如我的有“http,net.tcp”,在我的绑定中我有“http: :94:,net.tcp:194:”
I don't know of any good way to remotely check that IIS is configured correctly or the Windows Service is running. Do you not have a server admin that can look at these values for you?
我不知道有什么好的方法可以远程检查 IIS 是否配置正确或 Windows 服务是否正在运行。您没有可以为您查看这些值的服务器管理员吗?
回答by Trisped
Is 127.0.0.1:808
the actual IP:Port reported in the error? If so then you need to fix the IP (127.0.0.1
is synonymous with localhost
, so that would be your local computer).
是127.0.0.1:808
实际的IP:端口报道错误?如果是这样,那么您需要修复 IP(127.0.0.1
与 同义localhost
,因此这将是您的本地计算机)。
Otherwise, this looks like a firewall issue.
否则,这看起来像是防火墙问题。
There are two common sources of a firewall:
防火墙有两种常见的来源:
- Router
- OS
- 路由器
- 操作系统
Router firewalls are usually found on the router which connects the internal network to the internet. In these cases you (or someone with access) will need to log into the router and forward the port to the IP for the machine. This is only required if the two computers which are trying to communicate are not on the same internal network.
For example if your computer is connecting through the internet to the server then setting up port forwarding is required. If both computers are on the same network in the same office then port forwarding is not required (cases where this is not true are common in larger companies, but then there is an IT or network person to deal with the port issues).
路由器防火墙通常位于将内部网络连接到 Internet 的路由器上。在这些情况下,您(或具有访问权限的人)需要登录路由器并将端口转发到机器的 IP。仅当尝试通信的两台计算机不在同一内部网络上时才需要这样做。
例如,如果您的计算机通过 Internet 连接到服务器,则需要设置端口转发。如果两台计算机在同一办公室的同一网络上,则不需要端口转发(这种情况在大公司中很常见,但有 IT 或网络人员来处理端口问题)。
Assuming your server is running Windows, you will need someone with Admin(?) access to log in and either open the port or allow your service to accept incoming requests. Since you indicated that you do not have access to the server I would suggest having the people in charge of the server verify the configuration.
假设您的服务器运行的是 Windows,您将需要具有 Admin(?) 访问权限的人才能登录并打开端口或允许您的服务接受传入请求。由于您表示您无权访问服务器,我建议让负责服务器的人员验证配置。
回答by SWeko
As I read it, the "unit test" obviously expects a WCF net.tcp endpoint at some localhost address. So, for that to work you could either
当我读到它时,“单元测试”显然期望在某个本地主机地址有一个 WCF net.tcp 端点。所以,为了让它工作,你可以
- Add the required service on the build server, which might be a shared server, or owned by another team, or some other issue I'm not privy to, or
- Change the unit test, so that it does not expect a real live WCF service, but a mocked or faked one.
- 在构建服务器上添加所需的服务,这可能是共享服务器,或由另一个团队拥有,或其他一些我不知道的问题,或者
- 更改单元测试,使其不期望真正的实时 WCF 服务,而是模拟或伪造的服务。
I (obviously) recommend the second alternative.
我(显然)推荐第二种选择。