MGSoto
MGSoto

Reputation: 2363

How do I get a client's address from a WCF Service Application?

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?

Upvotes: 5

Views: 3782

Answers (5)

Jenish Zinzuvadiya
Jenish Zinzuvadiya

Reputation: 1085

You can use something like following OperationContext.Current.IncomingMessageHeaders.To.Host

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1062780

In 3.0, this is quite hard; but was improved in 3.5 (read Detect Client IP in WCF 3.5). I'm not aware of an event, though.

Upvotes: 7

Yohanis
Yohanis

Reputation: 31

It would have been easier if the WCF host provides a way of getting the service requester IP - so that you can call that method to get the original requester.

Upvotes: 1

Tangurena
Tangurena

Reputation: 2131

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).

Upvotes: 2

John Saunders
John Saunders

Reputation: 161773

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.

Upvotes: 2

Related Questions