简体   繁体   English

获取WCF中回调通道的IP地址

[英]Obtaining IP Address of Callback Channel in WCF

I have a WCF service on a duplex channel, with a callback contract.我在双工通道上有一个 WCF 服务,带有回调合同。 The service keeps track of the clients by storing the result of OperationContext.Current.GetCallbackChannel<T>() in a list when a client calls a SubscribeMe() method on the service.当客户端在服务上调用SubscribeMe()方法时,服务通过将OperationContext.Current.GetCallbackChannel<T>()的结果存储在列表中来跟踪客户端。 The service will periodically ping these callback channels to keep track of their validity, and expire those that are closed or timing out.该服务将定期 ping 这些回调通道以跟踪其有效性,并使那些已关闭或超时的通道过期。

The question I have is this: How do I get information about the remote host when the remote host is not actively making a request to my service, such as when I'm calling MyCallbackContract.Ping() ?我的问题是:当远程主机没有主动向我的服务发出请求时,例如当我调用MyCallbackContract.Ping()时,我如何获取有关远程主机的信息?

I tried casting the callback channel object to IContextChannel , and accessing the IContextChannel::RemoteAddress property, but this property contains some kind of namespace URI that has nothing to do with the actual remote host on the callback channel.我尝试将回调通道 object 转换为IContextChannel ,并访问IContextChannel::RemoteAddress属性,但此属性包含某种与回调通道上的实际远程主机无关的命名空间 URI。

Not tested (would take a while to get all the config set up,): but I think you're looking for something like this:未经测试(需要一段时间才能设置所有配置):但我认为您正在寻找这样的东西:

OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
                messageProperties[RemoteEndpointMessageProperty.Name]
                as RemoteEndpointMessageProperty;

var address = endpointProperty.Address;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM