WCF 3.5 RemoteEndpointMessageProperty in load balancing situation

John Dow

Usenet Archive
Joined
Oct 9, 2007
Messages
9
Reaction score
0
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.molad

Usenet Archive
Joined
Oct 14, 2012
Messages
1
Reaction score
0
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

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;
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top