Reputation: 185
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:
Upvotes: 3
Views: 6347
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:
Upvotes: 4