Welcome to WindowsClient.net | Sign in | Join

Zuker On Foundations

The realm of .NET (WPF, WCF and all around)

WCF 3.5 - Detect Client IP

Following this post.

As said in the post, WCF v3.5 includes easy access to the caller IP.
I can see where I would need this information, it is pretty important in some scenarios that I can think of.

Note that the code will not work 100% of the times.
It depends on the binding you're using and the composition of the message that the client sends.

I guess you could always process the ReplyTo header as part of the WS-Addressing protocol, even in 3.0, but here's another way to go at it.

The service side code to get the client IP:

OperationContext context = OperationContext.Current;

MessageProperties messageProperties = context.IncomingMessageProperties;

RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

 

return string.Format("Hello {0}! Your IP address is {1} and your port is {2}", value, endpointProperty.Address, endpointProperty.Port);

Posted: Feb 25 2008, 08:38 AM by zuker | with no comments
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Page view counter