WCF 3.5 RemoteEndpointMessageProperty in load balancing situation

Discussion in 'ASP .Net Web Services' started by John Dow, Jan 2, 2009.

  1. John Dow

    John Dow Guest

    I have a WCF service in .Net 3.5 and I am trying to use
    RemoteEndpointMessageProperty to get the IP address of the client who
    consume the service, for trouble shooting purposes:

    OperationContext context = OperationContext.Current;
    MessageProperties properties = context.IncomingMessageProperties;
    RemoteEndpointMessageProperty endpoint =
    properties[RemoteEndpointMessageProperty.Name] as
    if (endpoint != null)
    IP = string.Concat(endpoint.Address, ":", endpoint.Port);

    However, since the WCF service is hosted in IIS behind a load balancer, the
    IP address I got is always the IP of the load balancer.
    Is there any way to get around this so that I can get the true IP of the

    John Dow, Jan 2, 2009
    1. Advertisements

  2. John Dow

    eyal.molad Guest

    string retIp = "";

    OperationContext context = OperationContext.Current;

    MessageProperties prop = context.IncomingMessageProperties;

    HttpRequestMessageProperty endpointLoadBalancer =
    prop[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;

    retIp = endpointLoadBalancer.Headers["X-Forwarded-For"];

    RemoteEndpointMessageProperty endpoint =
    prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    retIp = endpoint.Address;
    catch (Exception ex) {
    log.Error("Error in GetClientIP: " + ex.ToString());
    return retIp;
    eyal.molad, Oct 15, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.