简体   繁体   English

Delphi XE2 DataSnap - 访问服务器方法模块中的REST连接属性

[英]Delphi XE2 DataSnap - Access REST connection properties in server methods module

I'm building an XE2 DataSnap server which will serve connections from REST clients. 我正在构建一个XE2 DataSnap服务器,它将为REST客户端提供连接。 My DSServerClass LifeCycle property is set to 'Invocation'. 我的DSServerClass LifeCycle属性设置为“Invocation”。 The REST connection properties will include username and password, which are handled through the DSAuthenticationManager UserAuthenticate() event. REST连接属性将包括用户名和密码,这些用户名和密码通过DSAuthenticationManager UserAuthenticate()事件处理。 What I need to know is how can I access the username and password within the server methods class? 我需要知道的是如何在服务器方法类中访问用户名和密码? I want to be able to know which REST username/password launched the object instance of my server class. 我希望能够知道哪个REST用户名/密码启动了我的服务器类的对象实例。

You can use DSServerClass.OnPrepare for that: 您可以使用DSServerClass.OnPrepare:

procedure TServerContainerTest.DSServerClass1Prepare(
  DSPrepareEventObject: TDSPrepareEventObject);
begin
  // Add username property to TServerMethodsTest
  if DSPrepareEventObject.MethodInstance is TServerMethodsTest then
    TServerMethodsTest(DSPrepareEventObject.MethodInstance).Username := DSPrepareEventObject.UserName;
end;

There's is no password available. 没有密码可用。 Don't use Server LifeCycle for this! 不要使用Server LifeCycle!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM