正如问题标题所述,在VM环境中运行时,我的WCF通信不起作用。 VM是与主机系统相同的Windows 7 x64。
我有一个运行.Net窗体客户端的.Net服务,试图连接到该服务。在物理机器上,它没有任何错误。当我在VM中运行它时,我在尝试注册服务时遇到错误。错误是
There was an error reading from the pipe. The pipe has been ended. (109, 0x6d).
异常中的HResult值是
-2146233087 (0x80131501)
并且堆栈跟踪在
结束System.ServiceModel.Channels.PipeConnection.Read()
如果它适用于主机系统,我无法看到它是一个编码问题。我也在其他一些没有任何问题的项目中重复使用相同的代码框架(尽管我还没有对VM中的那些进行过测试)。但是因为人们通常会问这里有一些片段
<ServiceContract(CallbackContract:=GetType(ClientCallback))> _
Public Interface ClientInterface
<OperationContract(IsOneWay:=False)> _
Function RegisterClient() As Integer
<OperationContract(IsOneWay:=False)> _
Function ShutDown() As Integer
End Interface
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.Single, IncludeExceptionDetailInFaults:=True, ConcurrencyMode:=ConcurrencyMode.Single)> _
Public Class ClientFunctions
Implements ClientInterface
Public Function ShutDown() As Integer Implements ClientInterface.ShutDown
'Do Stuff
End Function
Public Function RegisterClient() As Integer Implements ClientInterface.RegisterClient
Dim channel = OperationContext.Current.GetCallbackChannel(Of ClientCallback)()
'Do Stuff
End Function
End Class
Try
gClientPipe = New ServiceHost(GetType(ClientFunctions), New Uri() {New Uri("net.pipe://localhost")})
gClientPipe.AddServiceEndpoint(GetType(ClientInterface), New NetNamedPipeBinding(), "ClientSvc")
gClientPipe.BeginOpen(AddressOf OnConnectPipe, gClientPipe)
Catch ex As Exception
'Error
End Try
Dim cscb As New ClientCallbackClass
Dim ret As Integer = 0
Try
gCaPipeFactory = New DuplexChannelFactory(Of ClientInterface)(cscb, New NetNamedPipeBinding(), New EndpointAddress("net.pipe://localhost/ClientSvc"))
gCaPipeProxy = gCaPipeFactory.CreateChannel()
ret = gCaPipeProxy.RegisterClient() <- ERROR
Catch ex As Exception
ret = 0
End Try
我在主机和虚拟机上都以管理员身份运行,所以除非涉及其他一些权限,否则我无法看到问题与服务和应用程序之间的隔离限制相同。
如果异常更加详细,那就太好了,因为我很难搞清楚这个。