Search code examples
c#wcfoperationcontext

How to retrieve the client's machine name from within a WCF Operation Contract?


I'm currently looking at the OperationContect.Current properties. Is there a (nested) property the will always return the machine name of the client? I'm currently using net.tcp binding, but would like to support additional bindings in the future.

Using .NET 3.5 SP1


Solution

  • You can get the remote endpoint's IP address from the current OperationContext's IncomingMessageProperties, eg:

    RemoteEndpointMessageProperty messageProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    Console.WriteLine("Remote address is: {0}", messageProperty.Address);