drwatson
drwatson

Reputation:

Get IP in WCF RIA Services

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.

Upvotes: 2

Views: 699

Answers (2)

SeyedPooya Soofbaf
SeyedPooya Soofbaf

Reputation: 2649

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();
    }
};

Upvotes: 1

Nikhil Kothari
Nikhil Kothari

Reputation: 5225

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

Upvotes: 3

Related Questions