C# – How to get the client IP address from the request made to webservice

cfile uploadnetweb services

I have a webservice hosted in my IIS… I need to find out the clientIP address when the client use my service directly

like http://MyIpAddress/MyApplication/MyWebServiceClass.asmx

and is it possible to read file from the client machine? If so how can I do it?

Best Answer

You should have a plain old HTTP Context at your disposal in ASMX:

        HttpContext.Current.Request.UserHostAddress

Also re: "Is it possible to read a file from the client machine" - this all depends on your implementation. If you're making a web service for your intranet and you work in a small(ish) business environment, you probably can given the proper planning w/ your network guy (not advocating this as a good idea, just a possibility).

To further elaborate, if you are in your small office environment and you get a request from 192.168.1.55 and you know that every client machine in your network has a lastLoginData.txt file in the C drive, AND you have the appropriate configurations for UNC access to the client by the machine hosting the service, getting at "\\" + ip + "\c$\lastLoginData.txt" would be possible. You'd be creating a potentially horrible security issue for yourself, but it'd be possible.

In most normal cicumstances though, no, you will not have access to client disk from the Web Service - some sort of upload will likely have to occur first.