Reputation: 5859
Hey, how do you get the IP address of the person making a request in something like the following:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public partial class UsersService
{
[WebInvoke(UriTemplate = "", Method = "PUT")]
public User AddNewUser(User newUser)
{
// code goes here including GETTING AN IP??
}
Thanks!
Upvotes: 21
Views: 14690
Reputation: 364249
Inside AddNewUser use following snippet:
OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
RemoteEndpointMessageProperty instance offers Address and Port properties.
Upvotes: 39