简体   繁体   中英

Obtaining IP Address of Callback Channel in WCF

I have a WCF service on a duplex channel, with a callback contract. 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. The service will periodically ping these callback channels to keep track of their validity, and expire those that are closed or timing out.

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() ?

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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