locked
How to get client ip in WCF Service RRS feed

  • Question

  • User-776477372 posted

    Hi friend,

    how to get client ip in wcf serivice on multi server with load balancer?

    The WCF service is hosted on many servers and a load balancer. 

    Tuesday, May 20, 2014 11:24 AM

All replies

  • User-417640953 posted

    how to get client ip in wcf serivice on multi server with load balancer?

    The WCF service is hosted on many servers and a load balancer. 

    Hi sarvesh.mca,

    Thank you post the issue to asp.net forum.

    For getting client side IP address in WCF server side, please try below code.

    OperationContext context = OperationContext.Current;
    MessageProperties myprop = context.IncomingMessageProperties;
    RemoteEndpointMessageProperty endpoint = myprop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    string ip = endpoint.Address;

    Hope that helps, thanks.

    Best Regards!

    Wednesday, May 21, 2014 3:40 AM
  • User-776477372 posted

    Hi 

    i hava already used this code. when i am using this code i still get the ip of loadbalancer and not the client's ip address.

    Thanks & regards

    sarevsh

    Wednesday, May 21, 2014 7:23 AM
  • User1565039490 posted

    Look like you can set up various option (including real ip) through your load balancer firmware. You'd better check help documentation of your load balancer.

    http://www.rackspace.com/knowledge_center/article/why-does-every-visitor-to-my-cloud-sites-website-have-the-same-ip-address

    Wednesday, May 21, 2014 9:44 AM
  • User-776477372 posted

    i have install Advanced Logging for IIS on multi server

    http://www.iis.net/learn/extensions/advanced-logging-module/advanced-logging-for-iis-custom-logging

    but how can get  ip addresss in WCF?

    OperationContext context = OperationContext.Current;
    int index = context.IncomingMessageHeaders.FindHeader("HTTP_X_FORWARDED_FOR", "");

    Thursday, May 22, 2014 3:37 AM
  • User-417640953 posted

    Hello,

    i have install Advanced Logging for IIS on multi server

    As mentioned, "When deployed in proxy mode, by default the Barracuda Web Application Firewall appears as the source IP address in the requests

    it forwards to the back-end servers. For servers on the back-end needing to access the actual client IP address, the Barracuda Web Application

    Firewall provides two configurable ways to achieve this: Client Impersonation and X-Forwarded-For Header".

    For detail information, I suggest you follow below article.

    https://techlib.barracuda.com/waf/howtomakeclientipavailabletoserver

    Thanks.

    Regards!

    Thursday, May 22, 2014 6:11 AM
  • User-776477372 posted

    hi Fuxiang,

    what is code of get client IP in wcf service.

    Friday, May 23, 2014 5:45 AM
  • User-417640953 posted

    Hi,

    As for your client is behind a load balanced proxy, I think the client IP address not stable and we unneccessary to get the client IP.

    "If your client IP is on the same network you should be able to get the IP.  But if it's not it's important to remember

    how internet routing and network address tables (NAT) work". For more information, I suggest you take a look at below similar issue.

    http://www.codeproject.com/Questions/404504/Get-client-IP-address-in-a-WCF-Service-hosted-usin

    Hope it helps, thanks.

    Regards!

    Wednesday, May 28, 2014 10:47 PM
  • User-776477372 posted

    Hi,

    i hava already used this code.

    OperationContext context = OperationContext.Current;
       MessageProperties prop = context.IncomingMessageProperties;
       RemoteEndpointMessageProperty endpoint =
          prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
       string ip = endpoint.Address;
     
       return ip ;

    Tuesday, June 3, 2014 9:32 AM