2
votes

Does anybody know how can I get IP address of client with RIA services. In WCF we have OperationContext for that. But it doesn't work with RIA services.

2
no aswers, i guess there is now any way to do it...drwatson

2 Answers

3
votes

You can use HttpContext.Current and APIs off of that today...

1
votes

You can use an Invoke Operation in your DomainService to get the IP adress like this:

[Invoke]
public string GetIPAddress()
{
    return HttpContext.Current.Request.UserHostName;
}

In the client you should write:

YourContext context = new YourContext();

InvokeOperation invokeOperation = context.GetIPAddress();

invokeOperation.Completed += (s, args) =>
{
    if (invokeOperation.HasError)
    {
        MessageBox.Show("Error");
        invokeOperation.MarkErrorAsHandled();
    }
    else
    {
        string ip = invokeOperation.Value.ToString();
    }
};