#1 2012-08-05 09:25:52

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Interfaced-based services parameters (TSQLRestServerCallBackParams)

I'm trying to change from the old style services to interface-based sevices. With the mORMort samples the function delcarations change in sample 6 to 14 from/to:

function TServiceServer.Sum(var aParams: TSQLRestServerCallBackParams): Integer;
var a,b: Extended;
begin
  if not UrlDecodeNeedParameters(aParams.Parameters,'A,B') then begin
    result := 404; // invalid Request
    aParams.ErrorMsg^ := 'Missing Parameter'; // custom error message
    exit;
  end;
  while aParams.Parameters<>nil do begin
    UrlDecodeExtended(aParams.Parameters,'A=',a);
    UrlDecodeExtended(aParams.Parameters,'B=',b,@aParams.Parameters);
  end;
  aParams.Resp := JSONEncodeResult([a+b]);
  // same as : aResp := JSONEncode(['result',a+b],TempMemoryStream);
  result := 200; // success
end;

function TServiceCalculator.Add(n1, n2: integer): integer;
begin
  result := n1+n2;
end;

The problem I'm having is that I was using aParams to access TAuthSession.User.data and then creating a PDF file as the result and changing the aParams.header to the required content-type. With the interface-based services how can to access TSQLRestServerCallBackParams to do this?

Thanks for any help, I'm probably missing something obvious.

Offline

#2 2012-08-05 16:57:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: Interfaced-based services parameters (TSQLRestServerCallBackParams)

In your case, you can:
- Return custom content from an interface-based service, like a pdf - see http://blog.synopse.info/post/2012/03/2 … ed-service
- Access the caller context (e.g. session, user) from a global threadvar, defined as such:

threadvar
  /// this thread-specific variable will be set with the currently running
  // service context (on the server side)
  // - is set by TServiceFactoryServer.ExecuteMethod() just before calling the
  // implementation method of a service, allowing to retrieve the current
  // execution context
  // - its content is reset to zero out of the scope of a method execution
  // - when used, a local copy or a PServiceRunningContext pointer should better
  // be created, since accessing a threadvar has a non negligible performance cost
  ServiceContext: TServiceRunningContext;

But you are right, this was not clearly stated in the documentation.
I've completed it. See http://synopse.info/fossil/info/aecd1f1d2c

Thanks for the feedback.

Offline

#3 2012-08-06 07:46:00

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: Interfaced-based services parameters (TSQLRestServerCallBackParams)

Thanks, got it now.

Offline

Board footer

Powered by FluxBB