4
votes

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.

1

1 Answers

5
votes

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;