Getting the IP address of the callback channel in WCF

I have a WCF service on a duplex channel with a callback contract. The service monitors clients by storing the result of OperationContext.Current.GetCallbackChannel<T>() in the list when the client calls the SubscribeMe() method in the service. The service will periodically ping these callback channels in order to track their validity and expire those that are closed or fail.

I have a question: how to get information about the remote host when the remote host does not actively request my service, for example, when I call MyCallbackContract.Ping() ?

I tried to make the IContextChannel callback channel object and access the IContextChannel::RemoteAddress property, but this property contains some namespace URI that has nothing to do with the actual remote host in the callback channel.

+4
source share
1 answer

Not tested (it will take some time to configure all the settings!), But I think you are looking for something like this:

 OperationContext context = OperationContext.Current; MessageProperties messageProperties = context.IncomingMessageProperties; RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; var address = endpointProperty.Address; 
+5
source

All Articles