获取通过WCF拨打电话的客户端的主机名?

Oma*_*eji 0 .net c# wcf

有没有办法获取cleint的主机名在WCF中调用net.tcp绑定.我正在尝试诊断一个问题,我想找出哪个客户端正在向我发送导致它的消息.

我试过了:

OperationContext.Current.Channel.RemoteAddress.Uri.AbsoluteUri
Run Code Online (Sandbox Code Playgroud)

但这似乎只给我一个通用架构而不是主机名/ IP地址.

nit*_*one 6

我认为RemoteAddress仅对双工通道有效.你需要的是RemoteEndpointMessageProperty,如:

var remp = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string addr = remp.Address;
// do a DNS lookup or whatever from here if you want the hostname
Run Code Online (Sandbox Code Playgroud)