user564042
user564042

Reputation: 185

Getting Requester Info In WCF Service

I am working on a service that will support mobile applications on the Android, BlackBerry, iOS, and WP7 platforms. These applications will connect to various REST-based WCF services that I am working on. I would like to see what information a client application passes to my service. In an effort to do this, I've written the current operation in my WCF service:

[OperationContract]
[WebGet(UriTemplate = "/GetRequesterInfo")]
public string GetRequesterInfo()
{
  OperationContext context = OperationContext.Current;

  string message = "Session ID: " + context.SessionId;
  return message;
}

When I call this code, I notice that the SessionId is an empty string. In addition, I would like to get as much information about the client as possible. For instance, if this were ASP.NET, I could use the HttpRequest object and get:

While there are more properties, I'm sure you get the idea. This leads me to several questions:

  1. How do I get the request thread associated with the request to my WCF service? I thought that's what OperationContext was for. But I'm open to correction.
  2. How do I get all of the property name / values associated with a request to a WCF service?
  3. Am I asking for something that makes sense or am I off my rocker? It seems like I should be able to get some info about the requesting client.

Upvotes: 3

Views: 6347

Answers (1)

H.Wolper
H.Wolper

Reputation: 709

You can use System.ServiceModel.Channels.MessageProperties :

OperationContext context = OperationContext.Current;

if (context != null)
{
    MessageProperties messageProperties = context.IncomingMessageProperties;

If the request actually came from a browser, you can get a HttpRequest object, which is what you asked for.

Here's a screen capture of my MessageProperties, it should give you enough information on how to access these properties:

alt text

Upvotes: 4

Related Questions