【发布时间】:2011-07-13 19:39:54
【问题描述】:
我在 Window 7 x64 机器上进行开发工作,部署到 Windows 2008 x32 服务器。目前我正在向一些内部应用程序添加 WCF 服务,以便我们可以使用 net.tcp 绑定构建更小的客户端,这些绑定向用户报告服务器正在执行的操作,而无需运行多个服务器实例。为了减少应用程序需要多少管理,我尝试在我的第一个服务器应用程序上启用端口共享。我正在使用该应用程序自托管 WCF 服务,以便在必要时可以轻松地将它们从一台服务器移动到另一台服务器。这是启动服务器的代码:
Dim _service_host As ServiceHost
Dim active_server_address As Uri = New UriBuilder("net.tcp", "localhost", CInt(My.Settings.ServerPort)).Uri
_service_host = New ServiceHost(GetType(UpdateServiceOps), active_server_address)
_service_host.AddServiceEndpoint(GetType(IUpdateService), New NetTcpBinding With {.Name = "endpoint_tcp"}, "MiddlewareEndpoint")
_service_host.Description.Behaviors.Add(New ServiceMetadataBehavior)
_service_host.AddServiceEndpoint(GetType(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding, "mex")
_service_host.Open()
效果很好。但是,当我将其更改为以下内容时,出现错误。代码如下:
Dim _service_host As ServiceHost
Dim active_server_address As Uri = New UriBuilder("net.tcp", "localhost", CInt(My.Settings.ServerPort)).Uri
_service_host = New ServiceHost(GetType(UpdateServiceOps), active_server_address)
_service_host.AddServiceEndpoint(GetType(IUpdateService), New NetTcpBinding With {.Name = "endpoint_tcp", .PortSharingEnabled = True}, "MiddlewareEndpoint")
_service_host.Description.Behaviors.Add(New ServiceMetadataBehavior)
_service_host.AddServiceEndpoint(GetType(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding, "mex")
_service_host.Open()
当我在最后一行放置断点时出现以下错误:Unable to automatically step into the server. Connecting to the server machine 'nettcpportsharing' failed. The requested name is valid, but no data of the requested type was found. Try...Catch 块外壳代码显示异常类型为 AddressAlreadyInUseException...但是当我运行 netstat 时我没有看不到在该地址上监听的任何其他内容。在我的解决方案中的任何地方都没有出现“nettcpportsharing”。我已检查以确保 Net.Tcp 端口共享服务已启动。有什么想法吗?
【问题讨论】:
-
您是否开启/开启了tcp端口共享服务?
-
您的意思是“Net.Tcp 端口共享服务”,从 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SMSvcHost.exe 运行?是的。甚至重新启动它只是为了确定。