[英]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. 我正在开发一项支持Android,BlackBerry,iOS和WP7平台上的移动应用程序的服务。 These applications will connect to various REST-based WCF services that I am working on.
这些应用程序将连接到我正在处理的各种基于REST的WCF服务。 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:
为了做到这一点,我在WCF服务中编写了当前操作:
[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. 当我调用此代码时,我注意到
SessionId
是一个空字符串。 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: 例如,如果这是ASP.NET,我可以使用
HttpRequest
对象并获取:
While there are more properties, I'm sure you get the idea. 虽然有更多的属性,但我相信你明白了。 This leads me to several questions:
这引出了几个问题:
You can use System.ServiceModel.Channels.MessageProperties
: 您可以使用
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. 如果请求实际来自浏览器,您可以获得
HttpRequest
对象,这就是您要求的对象。
Here's a screen capture of my MessageProperties
, it should give you enough information on how to access these properties: 这是我的
MessageProperties
的屏幕截图,它应该为您提供有关如何访问这些属性的足够信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.