Doubt how to use XDataWebClient.RawInvoke

I'm trying to get a class from the server but the properties come with null value.


ERROR
Uncaught TypeError: Cannot read property 'Fserie' of null


Example SERVER
function TModelTeste.nfeChaveDeserializer(in_chave: String): TNFeChave;
begin
  if Length(in_chave) <> 44 then
    raise Exception.Create('Chave NF-e invalida');

  Result := TNFeChave.Create;
  Result.uf := Copy(in_chave, 1, 2);
  Result.anomes := Copy(in_chave, 3, 4);
  Result.cnpj := Copy(in_chave, 7, 14);
  Result.modelo := Copy(in_chave, 21, 2);
  Result.serie := Copy(in_chave, 23, 3);
  Result.numero := Copy(in_chave, 26, 9);
  Result.codigo := Copy(in_chave, 35, 9);
  Result.digito := Copy(in_chave, 44, 1);
end;



Client:
procedure TFViewnotaPopup.nfeChaveDeserializer;
  procedure OnResult(Response: TXDataClientResponse);
  var
    fNFeChave: TNFeChave;
  begin
    fNFeChave := TNFeChave.Create;
    try
      fNFeChave := TNFeChave(TJSObject(Response.Result)['value']);
      edserie_nf.Text := fNFeChave.serie;       <<<<<<<<<<<============ ERROR
      ednumero.Text := fNFeChave.numero;
    finally
      fNFeChave.Free;
    end;
  end;

begin
  XDataWebClient.RawInvoke('IModelTeste.nfeChaveDeserializer', [edchave.Text], @OnResult);
end;
In TMS Web Core you can't cast a TJSObject to a TNFeChave (which inherits from TObject). They are unrelated, not compatible classes. You have to use TJSObject directly.

Is this how I should use it on the server side?

function TModelNotaPremiada.nfeChaveDeserializer(in_chave: String): TJSObject;
var
  vNFeChave: TNFeChave;
begin
  if Length(in_chave) <> 44 then
    raise Exception.Create('Chave NF-e invalida');

  vNFeChave := TNFeChave.Create;
  vNFeChave.uf := Copy(in_chave, 1, 2);
  vNFeChave.anomes := Copy(in_chave, 3, 4);
  vNFeChave.cnpj := Copy(in_chave, 7, 14);
  vNFeChave.modelo := Copy(in_chave, 21, 2);
  vNFeChave.serie := Copy(in_chave, 23, 3);
  vNFeChave.numero := Copy(in_chave, 26, 9);
  vNFeChave.codigo := Copy(in_chave, 35, 9);
  vNFeChave.digito := Copy(in_chave, 44, 1);

{$IFDEF PAS2JS}
  Result := TJSJSON.parseObject(vNFeChave);
{$ENDIF}
end;

You don't need to change server side. Your original one was ok.



It worked, thank you.