Skip to content

Instantly share code, notes, and snippets.

@mythz
Created December 17, 2010 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/744701 to your computer and use it in GitHub Desktop.
Save mythz/744701 to your computer and use it in GitHub Desktop.
Get IP address of WCF Service
public static IPAddress GetIpAddress(System.ServiceModel.OperationContext context)
{
var prop = context.IncomingMessageProperties;
if (context.IncomingMessageProperties.ContainsKey(System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name))
{
var endpoint = prop[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name]
as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
if (endpoint != null)
{
return IPAddress.Parse(endpoint.Address);
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment