Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on a web service to WCF migration project. In my old web service, I have following piece of code for gettign the client IP address

C#
Context.Request.ServerVariables["REMOTE_ADDR"])


I am hosting my new WCF service in a Windows service and using nettcpBinding(net.tcp) for better performance.
My concern is I want to replace the aboce piece of code with new code for getting the Client IP address in WCF.

Things I have tried already.

C#
public string GetClientIPAddress()
       {
           return ((RemoteEndpointMessageProperty)OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]).Address;
       }


but it returns IP address in this format ::1 (IPv6)

Is there anyway to get the client IP address in IPv4 form (11.12.13.140) ?


Thanks in advance.

"Happy Coding"
Posted
Comments
Sergey Alexandrovich Kryukov 26-Jul-13 1:00am    
If all addresses could get IPv4 "form", IPv6 wouldn't be needed... :-)
—SA

1 solution

IPv6 addressing was created to extend the total number of all possible IP addresses. IPv4 is not a different form of address. Got the hint?

Please see: http://en.wikipedia.org/wiki/IPv6[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900