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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With