#1 2015-01-15 14:19:14

Rob
Member
Registered: 2014-07-30
Posts: 8

501 error when using Variants or Composition CrossPlatform

Hi,

When using a TSQLRecord or a Variant as a property of a TSQLRecord instance and then passing that TSQLRecord instance as a Paramater to a service gives a 501 server error (while using the generated CrossPlatform Client).

Does that mean we are forced to use DTO's ? Or are we doing something wrong ?

Thanks in advance,

Rob

Offline

#2 2015-01-15 18:00:25

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

Re: 501 error when using Variants or Composition CrossPlatform

Hi Rob,

Which kind of CrossPlatform client are your using?
FireMonkey/Delphi I guess?

Do you have any more information about the problem?
Some simple code to reproduce?
A simple TSQLRecord which fails?

Offline

#3 2015-01-16 08:32:48

Rob
Member
Registered: 2014-07-30
Posts: 8

Re: 501 error when using Variants or Composition CrossPlatform

firemonkey indeed.
using this on the client gives 501 server error

lPatient := TSQLPatient.Create;
    lPatient.ID := AItem.Data['theID'].AsInteger;
    localPatAdmin.FillPatient(lPatient);

server side:

procedure TPatientAdministration.FillPatient(var thePatient: TSQLPatient);
begin
 thePatient :=  TSQLPatient.Create( ServiceContext.Request.Server, thePatient.ID);
end;

this is in the datamodel server side:

TSQLPatient = class(TSQLRecord)
  private
    FIsActive: boolean;
    FContact: TSQLContact;
published
    property IsActive: boolean read FIsActive write FIsActive;
    property Contact: TSQLContact read FContact write FContact;
end;

so everytime we pass a TSQLRecord as a parameter when we have a TSQLRecord property it gives this error or When there is a 'Variant' as a property.

I hope I was able to explain smile

Offline

#4 2015-01-16 08:38:30

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

Re: 501 error when using Variants or Composition CrossPlatform

First of all, your code is leaking memory.
As state by the documentation, you should NOT create the class instances passed as parameter.
They are created by the caller stub.

So what you should write is:

procedure TPatientAdministration.FillPatient(var thePatient: TSQLPatient);
begin
  ServiceContext.Request.Server.Retrieve(thePatient.ID);
end;

What is the exact error on the server side?
Could you please trace the server side with the debugger, or at least enable the logs and check out?

Offline

#5 2015-01-16 09:49:41

Rob
Member
Registered: 2014-07-30
Posts: 8

Re: 501 error when using Variants or Composition CrossPlatform

Thanks I changed my code to use Retrieve.

these are the last lines of the log, I ll see if i can get anything out of debug.

20150116 10445700  (  +    TSQLRestServerKineQuick(002FB420).0019337C mORMot.TSQLRestServer.URI (29497)
20150116 10445700  ( auth      TSQLRestRoutingREST(002D05C0) User/5939437
20150116 10445700  ( call      TSQLRestServerKineQuick(002FB420) PatientAdministration.FillPatient
20150116 10445700  ( srvr      POST kq/PatientAdministration.FillPatient ERROR=400 (Shared execution failed (probably due to bad input parameters) for IPatientAdministration.FillPatient)
20150116 10445700  (  -    00.000.230
20150116 10445708  )  +    TSQLRestServerKineQuick(002FB420).0019337C mORMot.TSQLRestServer.URI (29497)
20150116 10445708  ) auth      TSQLRestRoutingREST(002D05C0) User/5939437
20150116 10445708  ) call      TSQLRestServerKineQuick(002FB420) PatientAdministration.FillPatient

Offline

#6 2015-01-16 10:39:42

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

Re: 501 error when using Variants or Composition CrossPlatform

1. What is the input in Ctxt.ServiceParameters, before being sent to InternalExecute()?

2. What is the wrapper generated unit content?

Offline

#7 2015-01-16 13:25:31

Rob
Member
Registered: 2014-07-30
Posts: 8

Re: 501 error when using Variants or Composition CrossPlatform

this is in the ctxt.Serviceparameters:
'[{"ID":4,"ContactId":0,"HeadOfFamilyId":0,"PayerId":0,"IsActive":0,"MutualityId":0,"MutPayCode":0,"GMDHolderId":0,"ThirdPayer":"","OldID":"","PaysAfterBooking":0,"Profession":"","NumberOfChildren":0,"NotifyEmail":0,"NotifySMS":0,"NotifyAppointment":0,"Mutuality":null}]'


this is an excerpt of the mormotclient.pas:

  TSQLPatient = class(TSQLRecord)
  protected
    fContactId: Integer;
    fHeadOfFamilyId: Integer;
    fPayerId: Integer;
    fIsActive: Boolean;
    fMutualityId: Integer;
    fMutPayCode: Integer;
    fGMDHolderId: Integer;
    fThirdPayer: String;
    fOldID: String;
    fPaysAfterBooking: Boolean;
    fProfession: String;
    fNumberOfChildren: Integer;
    fNotifyEmail: Boolean;
    fNotifySMS: Boolean;
    fNotifyAppointment: Boolean;
    fMutuality: TSQLMutuality;
  published
    property ContactId: Integer read fContactId write fContactId;
    property HeadOfFamilyId: Integer read fHeadOfFamilyId write fHeadOfFamilyId;
    property PayerId: Integer read fPayerId write fPayerId;
    property IsActive: Boolean read fIsActive write fIsActive;
    property MutualityId: Integer read fMutualityId write fMutualityId;
    property MutPayCode: Integer read fMutPayCode write fMutPayCode;
    property GMDHolderId: Integer read fGMDHolderId write fGMDHolderId;
    property ThirdPayer: String read fThirdPayer write fThirdPayer;
    property OldID: String read fOldID write fOldID;
    property PaysAfterBooking: Boolean read fPaysAfterBooking write fPaysAfterBooking;
    property Profession: String read fProfession write fProfession;
    property NumberOfChildren: Integer read fNumberOfChildren write fNumberOfChildren;
    property NotifyEmail: Boolean read fNotifyEmail write fNotifyEmail;
    property NotifySMS: Boolean read fNotifySMS write fNotifySMS;
    property NotifyAppointment: Boolean read fNotifyAppointment write fNotifyAppointment;
    property Mutuality: TSQLMutuality read fMutuality write fMutuality;
  end;

...

procedure TServicePatientAdministration.FillPatient(var thePatient: TSQLPatient);
var res: TVariantDynArray;
begin
  fClient.CallRemoteService(self,'FillPatient',1, // raise EServiceException on error
    [ObjectToVariant(thePatient)],res);
  thePatient := TSQLPatient.CreateFromVariant(res[0]);
end;

Offline

#8 2015-01-16 20:30:29

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

Re: 501 error when using Variants or Composition CrossPlatform

How is your TSQLPatient defined on the server side?

Offline

#9 2015-01-19 08:21:36

Rob
Member
Registered: 2014-07-30
Posts: 8

Re: 501 error when using Variants or Composition CrossPlatform

like this:

 TSQLPatient = class(TSQLRecord)
  private
    FNISS: RawUTF8;
    FMutPayCode: Integer;
    FProfession, FThirdPayer: RawUTF8;
    FMutInfo: Variant;
    FNumberOfChildren: integer;
    FPayerId: integer;
    FGMDHolderId: integer;
    FContactId: integer;
    FMutualityId: integer;
    FHeadOfFamilyId: integer;
    FOldID: RawUTF8;
    FPaysAfterBooking: boolean;
    FNotifyEmail: boolean;
    FIsActive: boolean;
    FNotifyAppointment: boolean;
    FNotifySMS: boolean;
    FMutuality: TSQLMutuality;
  published
    property ContactId: integer read FContactId write FContactId;
    property HeadOfFamilyId: integer read FHeadOfFamilyId write FHeadOfFamilyId;
    property PayerId: integer read FPayerId write FPayerId;
    property IsActive: boolean read FIsActive write FIsActive;
    property MutualityId: integer read FMutualityId write FMutualityId;
    property MutPayCode: Integer read FMutPayCode write FMutPayCode;
    property GMDHolderId: integer read FGMDHolderId write FGMDHolderId;
    property ThirdPayer: RawUTF8 read FThirdPayer write FThirdPayer;
    property OldID: RawUTF8 read FOldID write FOldID;
    property PaysAfterBooking: boolean read FPaysAfterBooking write FPaysAfterBooking;
    property Profession: RawUTF8 read FProfession write FProfession;
    property NumberOfChildren: integer read FNumberOfChildren write FNumberOfChildren;
    property NotifyEmail: boolean read FNotifyEmail write FNotifyEmail;
    property NotifySMS: boolean read FNotifySMS write FNotifySMS;
    property NotifyAppointment: boolean read FNotifyAppointment write FNotifyAppointment;
    property Mutuality: TSQLMutuality read FMutuality write FMutuality;
  end;

Offline

#10 2015-01-19 11:20:49

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

Re: 501 error when using Variants or Composition CrossPlatform

And how is TSQLMutuality defined?

Offline

#11 2015-01-19 12:15:58

Rob
Member
Registered: 2014-07-30
Posts: 8

Re: 501 error when using Variants or Composition CrossPlatform

  TSQLMutuality = class(TSQLRecord)
  private
    FMutualityName: RawUTF8;
  published
    property MutualityName: RawUTF8 read FMutualityName write FMutualityName;
  end;

Offline

Board footer

Powered by FluxBB