Lazy Load + Proxy, http rest server

Hi,
  We have  aurelius + http+ DataSnap + rest on server side, client call server methods, how to implement a proxy to get  lazy load associations? is there a demo with server and client? I read the documentation, i can not understand
  Thanks

There is no demo, unfortunately. What is the problem you are having with the examples provided in documentation.

Hi
  Deserializer := TDataSnapJsonDeserializer.Create;
  try
    Deserializer.ProxyLoader := TJsonProxyLoader.Create(
      function(ProxyInfo: IProxyInfo): TObject
      var
        Serializer: TDataSnapJsonSerializer;
        Deserializer: TDataSnapJsonDeserializer;
        JsonObject: TJsonValue;
        StrProxy: string;
        StrJsonObject: string;
      begin
        Serializer:= TDataSnapJsonSerializer.Create;
        Deserializer := TDataSnapJsonDeserializer.Create;
        try
          StrProxy := Serializer.ToJson(ProxyInfo).ToJSON;
          JsonObject := RestConnection.SMUserXClient.RemoteProxyLoad(Serializer.ToJson(ProxyInfo));
          StrJsonObject := JsonObject.ToJSON;
          Result := Deserializer.FromJson(JsonObject, TObject); //ERROR here 'Cannot instantiate object. "$type" not specified or invalid in Json representation.
        finally
          Deserializer.Free;
          Serializer.Free;
        end;
      end
      );
    FUserX := Deserializer.FromJson<TUserX>(RestConnection.ServerMethodUserXClient.Get(1, False));
  finally
    Deserializer.Free;
  end;

  Nome := FUserX.EntityId.Name;
  Group := FUserX.UserGrpId.Description;

Sorry to insist, but a demo make my life better, thanks

Where does this code belongs to?


 Nome := FUserX.EntityId.Name;
  Group := FUserX.UserGrpId.Description;

and how is your SMUserXClient.RemoteProxyLoad method implemented?
What is the JSON sent/receive by this communication?

Hi, Wagner
  The code is just a copy adapted to my needs, on page 159/160 aurelius manual, the method RemoteProxyLoad, to.

...
var Nome, Group: String
...
   Nome := FUserX.EntityId.Name;             //Just To "Force" lazy Loads
  Group := FUserX.UserGrpId.Description;//Just To "Force" lazy Loads
...

// This methods assumes that Serializer, Deserializer and ObjectManager objects
// are already created by the server
function TSMUserX.RemoteProxyLoad(JsonProxyInfo: TJsonValue): TJsonValue;
var
  ProxyInfo: IProxyInfo;
begin
//  ProxyInfo := Deserializer.ProxyInfoFromJson<IProxyInfo>(JsonProxyInfo);//Compiler Message: Interface 'Proxy Info' has no interface identification
    ProxyInfo := Deserializer.ProxyInfoFromJson(JsonProxyInfo);
    Result := Serializer.ToJson(FManager.ProxyLoad(ProxyInfo));
end;

Thanks


What is the JSON sent/receive by this communication?

Hi
JSON Result(ServerMethodUserXClient.Get(1, False)):
'{"$type":"DB.Schema.TUserX","$id":1,"FUserPassword":"mvf","FChangePasswordNextLogin":0,"FUserGrpId":{"$proxy":"single","key":1,"class":"TUserX","member":"FUserGrpId"},"FId":1,"FUserName":"mvfuser","FUserEmail":"mvf@mvf.pt","FRecVersion":"2015-03-26 16:09:45.000","FEntityId":{"$proxy":"single","key":1,"class":"TUserX","member":"FEntityId"}}'

JSON Proxy on Server side(RemoteProxyLoad):
{"$proxy":"single","key":1,"class":"TUserX","member":"FEntityId"}

JSON Proxy on Server side(RemoteProxyLoad) Result:
{"$type":"DB.Schema.TMember","$id":1,"FIdentityCard":null,"FCellPhone":null,"FTIPOSALDO":null,"FCreditLineValue":741394,"FStartDirectTranfer":null,"FShipId":null,"FJobId":null,"FCivilStId":null,"FPhotoIdTN":null,"FNotSendMail":1,"FSuspendedCredit":1462036,"FNIB":null,"FEndDirectTransfer":"2001-05-23 03:03:38.000","FBankId":null,"FSaleManId":null,"FPayMechId":{"$proxy":"single","key":0,"class":"TEntDoc","member":"FPayMechId"},"FTitleId":null,"FPhotoId":{"$proxy":"single","key":15,"class":"TMember","member":"FPhotoId"},"FId":1,"FName":"Joaquim Moreno","FIdentList":{"$proxy":"list","key":1,"class":"TEntity","member":"FIdentList"},"FAUTOFATURACAO":365417,"FIdentityCardExpires":null,"FPhone":null,"FEmail":null,"FAZ_EntList":{"$proxy":"list","key":1,"class":"TEntity","member":"FAZ_EntList"},"FFax":"WHfNzcdCVzZJYNMlOSJu","FNotSendWarning":652344,"FBICSWIFT":"VPMvDplFUuYiUmc","FDiscounId":null,"FCountryId":{"$proxy":"single","key":1,"class":"TEntDoc","member":"FCountryId"},"FName2":"Moreno","FEntStatId":null,"FIBAN":null,"FBirthday":null,"FGenderId":1,"FPhone2":null,"FBalance":105041,"FREFERENCIAADD":null,"FCustomCod":"aaaaaaaaaaaaaaa","FPriceTag":210815,"FMailMechanism":1,"FEntityCreatedDate":"2001-02-01 15:53:20.000","FRecVersion":"2000-11-13 12:43:22.000","FTaxPayerNumber":null,"FPayTermId":{"$proxy":"single","key":0,"class":"TEntDoc","member":"FPayTermId"},"FTaxId":null}

thanks

JSON communication is correct, it seems there is nothing wrong with the code you posted.

The server is just not being able to find and instantiate an object of the class "DB.Schema.TMember".
I don't know the details of your server, but you could try to do that in your server side to see if it's working. Also be sure the linker didn't remove the class, by using something like

RegisterEntity(DB.Schema.TMember).

Hi, Wagner
  Good tip, my mistake, i forgot to include RegisterEntity(DB.Schema.TMember) on client side, solved
thanks to you :)