title: Getting Caller IP in WebMethod
body: <p>I have two projects hosted in IIS. First is GUI second WebServices.
  I have to get a caller IP address in WebServices (WebMethod).</p>
  
  <p>I Tried:</p>
  
  <pre><code>Context.Request.UserHostAddress
  HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
  Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
  </code></pre>
  
  <p>First two return::1
  third return null.</p>
  
  <p>When I try them in GUI code behind right before calling WebMethot I get correct IP addresses.
  How can I get a Caller IP address in WebMethod?</p>
  
  <p>I use ASP Net 4.0</p>
  
  <p>-- Edit</p>
  
  <p>What I mean is that both projects are hosted on server. </p>
  
  <p>Let's say servers IP is 192.168.0.2.
  My IP is 192.168.0.3.</p>
  
  <p>I'am opening webbrowser and type <a href="http://192.168.0.2/GUI" rel="nofollow noreferrer">http://192.168.0.2/GUI</a>. And after I click a button, on code behind Context.Request.UserHostAddress == 192.168.0.3 which is correct.</p>
  
  <p>Button calls WebMethod on the same server <a href="http://192.168.0.2/services/service.asmx" rel="nofollow noreferrer">http://192.168.0.2/services/service.asmx</a> and there Context.Request.UserHostAddress == ::1 I think it is correct because GUI is hosted on the same server that services are. </p>
  
  <p>My question is how can I get my IP (192.168.0.3) insted ::1. </p>
  
  <p>I tried Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] but it is empty.</p>