Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WCF 3.5 RemoteEndpointMessageProperty in load balancing situation

445 views
Skip to first unread message

John Dow

unread,
Jan 2, 2009, 11:31:50 AM1/2/09
to
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
RemoteEndpointMessageProperty;
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
client?

Thanks

eyal....@gmail.com

unread,
Oct 14, 2012, 10:59:27 PM10/14/12
to John Dow
string retIp = "";
try
{

OperationContext context = OperationContext.Current;

MessageProperties prop = context.IncomingMessageProperties;

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

if(endpointLoadBalancer.Headers["X-Forwarded-For"]!=null)
{
retIp = endpointLoadBalancer.Headers["X-Forwarded-For"];
}

if(string.IsNullOrEmpty(retIp))
{
RemoteEndpointMessageProperty endpoint =
prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
retIp = endpoint.Address;
}
}
catch (Exception ex) {
log.Error("Error in GetClientIP: " + ex.ToString());
}
return retIp;
0 new messages