As part of our company security policy we need to obtain the client ip address as part of the authentication process in our custom UserNameSecurityTokenHandler (Note, we are using our custom UserNameSecurityTokenHandler over wsHttp binding). Unfortunately, the following code blows up with a NullReferenceException because OperationContext is null.
public string GetAddress()
{
//http://www.danrigsby.com/blog/index.php/2008/05/21/get-the-clients-address-in-wcf/
RemoteEndpointMessageProperty clientEndpoint =
OperationContext.Current.IncomingMessageProperties[
RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
return clientEndpoint.Address;
}
Anyone know how to get the client IP address in the UserNameSecurityTokenHandler?