views:

416

answers:

3

How can I get a client's address from a WCF Service Application? Also, is there an event raised when a client connects, possibly with address information?

+4  A: 

In 3.0, this is quite hard; but was improved in 3.5 (see here). I'm not aware of an event, though.

Marc Gravell
+2  A: 

Which address are you looking for? The IP address?

If so, I hope you're aware of the limitations on that - it won't be accurate if the client's on the other side of a NAT device or Internet proxy.

John Saunders
I wasn't aware of the limitations, but for my application, NATs and proxies will not be a problem. I was hoping for an IP address or even a Windows PC name.
MGSoto
Ok, only other thing to think about is this: if the network topology changes, will they consult you first, or will the "networking" people assume they can change the network without permission from the "programming" people? Because that's how it usually works, and how it's meant to work.
John Saunders
If the topology changes, it should be as simple as changing a config file or two, but in the end, this will always be running on a local network.
MGSoto
Not so. There are several kinds of networking device which could be placed between you and those machines, which would prevent you from seeing their IP addresses. Another thing is that any of those machines could change their IP address, or add a second network card. In general, Application-layer stuff like yours has no business depending on Network-layer entities like an IP address.
John Saunders
+2  A: 

If System.Web.HttpContext.Current.Request.UserHostAddress isn't null, then it has the remote address. But that might be a proxy or load balancer (the case I have in our production environment).

Tangurena