Get client IP

Topics: Web Api
Sep 15, 2011 at 12:05 PM

Hello,

can I get client IP address inside the function that process POST request?

Something like that - 

 

[ServiceContract] public class HelloResource
{
	[WebInvoke(UriTemplate = "", Method = "POST")]
	public HttpResponseMessage Post(HttpRequestMessage request)
	{
		// get client IP
		...
	}
}

 

Sep 15, 2011 at 12:40 PM

Yes.  With the latest source you can do it like this:  http://webapicontrib.codeplex.com/SourceControl/changeset/view/b0f6427eb835#source%2fWebApi.IntegrationTests%2fTestService.cs

Sep 15, 2011 at 1:08 PM
Edited Sep 15, 2011 at 1:08 PM

It doesn't work. The code

var prop = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
throws exception "A property with the name 'System.ServiceModel.Channels.RemoteEndpointMessageProperty' is not present."
Sep 15, 2011 at 1:47 PM

Are you using the latest version of the source code?  The nuget is not likely to be updated until after the Build session today.

Coordinator
Sep 15, 2011 at 9:32 PM

Preview 5 is up on NuGet now (http://nuget.org/List/Packages/WebApi.All), so you should be able to try this out with our latest bits. Let us know if you run into any issues.

Sep 16, 2011 at 9:16 AM

With Preview 5 it works. Thank DarrelMiller and danroth27 for help. And another question - when is it planned to release stable version of WebAPI (not beta)?

Coordinator
Sep 16, 2011 at 4:49 PM

We are targeting shipping WCF Web API with the rest of the web platform in April of next year.

Daniel Roth

From: alart [email removed]
Sent: Friday, September 16, 2011 1:16 AM
To: Daniel Roth
Subject: Re: Get client IP [wcf:272675]

From: alart

With Preview 5 it works. Thank DarrelMiller and danroth27 for help. And another question - when is it planned to release stable version of WebAPI (not beta)?