gpt4 book ai didi

c# - WCF中获取回调 channel 的IP地址

转载 作者:太空狗 更新时间:2023-10-30 01:09:39 27 4
gpt4 key购买 nike

我在双工 channel 上有一个 WCF 服务,带有回调协定。该服务通过存储 OperationContext.Current.GetCallbackChannel<T>() 的结果来跟踪客户端在客户端调用 SubscribeMe() 时的列表中服务上的方法。该服务将定期 ping 这些回调 channel 以跟踪其有效性,并使那些已关闭或超时的 channel 过期。

我的问题是:当远程主机没有主动向我的服务发出请求时,我如何获取有关远程主机的信息,例如当我调用 MyCallbackContract.Ping() 时?

我尝试将回调 channel 对象转换为 IContextChannel ,并访问 IContextChannel::RemoteAddress属性,但此属性包含某种与回调 channel 上的实际远程主机无关的命名空间 URI。

最佳答案

未测试(设置所有配置需要一段时间!),但我认为您正在寻找这样的东西:

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

var address = endpointProperty.Address;

关于c# - WCF中获取回调 channel 的IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6262025/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com