English 中文(简体)
• 请求人信息
原标题:Getting Requester Info In WCF Service
  • 时间:2011-01-05 14:30:55
  •  标签:
  • c#
  • wcf

我正在从事一项服务,支持安伯、黑海、西里和WP7平台的移动应用。 这些申请将与我正在从事的各种基于教育、科学和技术发展、文化、文化、文化、文化、文化、文化、文化、文化、文化、文化、文化、文化、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言、语言 我想看到客户申请给我服务的信息。 为努力做到这一点,我撰写了目前我的全球合作框架工作:

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

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

当我称之为这一守则时,我注意到SessionId是一个空洞。 此外,我还要得到尽可能多的有关客户的信息。 例如,如果是协会。 NET,我可以使用<代码>。 HttpRequest Object andtake:

  • HttpMethod
  • IsLocal
  • IsSecureConnection
  • RequestType
  • Url.AbsoluteUri
  • Url.OriginalString
  • UserAgent
  • UserHostAddress
  • UserHostName
  • Browser.Id
  • Browser.Browser
  • Browser.CanInitiateVoiceCall
  • Browser.ClrVersion.Minor
  • Browser.Cookies
  • Browser.EcmaScriptVersion
  • Browser.GatewayVersion
  • Browser.InputType
  • Browser.MobileDeviceManufacturer
  • Browser.MobileDeviceModel

虽然财产较多,但我相信你会得到这一想法。 这导致我提出几个问题:

  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.
问题回答

You can use System.ServiceModel.Channels.MessageProperties :

OperationContext context = OperationContext.Current;

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

如果请求实际上来自浏览器,你可以找到<代码>。 HttpRequest Object, 这就是你要求的东西。

这里,在我<代码>MessageProperties的屏幕上,它应当向您提供充分的信息,说明如何获取这些财产:

“alt





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签