如何从WCF操作合同中检索客户端的计算机名称?

我目前正在查看OperationContect.Current属性。 是否有(嵌套)属性将始终返回客户端的计算机名称? 我目前正在使用net.tcp绑定,但希望将来支持其他绑定。

使用.NET 3.5 SP1

您可以从当前OperationContext的IncomingMessageProperties获取远程端点的IP地址,例如:

RemoteEndpointMessageProperty messageProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; Console.WriteLine("Remote address is: {0}", messageProperty.Address);