Reputation: 295
I have create a web service using wcf and publish in public. Now i want to get the system IP details of who is trying to access my services. I don't know whether its possible or not. If its possible means tell me that way.
Upvotes: 0
Views: 105
Reputation: 4569
Simple!
string ip = String.Empty;
var props = OperationContext.Current.IncomingMessageProperties;
var endpointProperty = props[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
if (endpointProperty != null)
{
ip = endpointProperty.Address;
}
NOTE It will work perfect after deployment. On localhost, it will give you Network loopback addresses. So, don't worry about that. Moreover! There will be different loopback addresses for IPv4 and IPv6.
Upvotes: 1
Reputation: 12430
All of the request information is passed along with the request as server variables. There are a whole bunch with all sorts of different information have a look at W3Schools list.
In the case of the IP address it is stored in the REMOTE_ADDR variable, you can quickly access this from the Request in a webservice using:
HttpContext.Current.Request.UserHostAddress;
Upvotes: 0
Reputation: 1639
You can use this to get IP Address.
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
Upvotes: 0