2013-04-09 3 views
0

SOAP 메시지를 생성하기 위해 작업 중이며 요청한 클라이언트 IP가 필요합니다. 클라이언트 IP를 찾을 수있는 방법을 찾지 못했습니다. 클라이언트로부터 요청을받을 때 클라이언트 IP를 찾을 수있는 단계를 알려주십시오.요청한 클라이언트의 IP 주소 얻기 (SOAP 메시지)

+0

가 왜 손으로 SOAP 메시지를 작성? 왜 "Add Service Reference"를 사용하지 않는가? –

답변

-1

그래서 서비스 내에서 웹 서비스를 사용하는 클라이언트의 IP 주소를보고 싶습니까?

일부 서버 변수를 검사하는 클래스를 만들 수 있습니다. 일부 클래스는 HTTP 헤더에서 데이터를 가져옵니다. 난 그냥 HTTP_X_FORWARDED_FOR보고 REMOTE_ADDR 트릭 않는 것으로 나타났습니다 (예를 C#으로.) :

public class IP 
{ 
    public static String UserHostAddress { get { return HttpContext.Current.Request.UserHostAddress; } } 
    public static String REMOTE_ADDR { get { return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } } 
    public static String HTTP_X_FORWARDED_FOR { get { return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } } 
    public static String HTTP_CLIENT_IP { get { return HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"]; } } 
    public static String HTTP_X_FORWARDED { get { return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED"]; } } 
    public static String HTTP_X_CLUSTER_CLIENT_IP { get { return HttpContext.Current.Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"]; } } 
    public static String HTTP_FORWARDED_FOR { get { return HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED_FOR"]; } } 
    public static String HTTP_FORWARDED { get { return HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED"]; } } 

    public static String IP_ADDRESS 
    { 
     get 
     { 
      if (HTTP_X_FORWARDED_FOR != null) 
      { 
       return HTTP_X_FORWARDED_FOR; 
      } 

      return REMOTE_ADDR; 
     } 
    } 
} 
+0

-1 : ASP.NET 웹 서비스에서만 작동합니다. –

+0

맞아, 나는 그가 정확히 묻고있는 것을 해석하지 못했다는 것을 깨달았다. – digiliooo

관련 문제