TXDataWebConnection expecting to get Model -> Exception

Basically i have this xData-Server-Method (defined as [httpGet] in the interface) which is fetching some rows from a table and i´m turning the result to JSON with TDatasetToJSONBridge. This works fine for itself i can request this via browser or postman. I get the JSON as i want.

function TTestService.GetPGMSampleData: TJSONObject;
var
  lJSONBridge: TDatasetToJSONBridge;
begin
  lJSONBridge := TDatasetToJSONBridge.Create;
  try
    if not MyFDConnection.Connected then
      MyFDConnection.Connected := True;

    MyFDQuery.SQL.Text := 'select * from MyTable';
    MyFDQuery.Active := True;

    lJSONBridge.Dataset := MyFDQuery;
    lJSONBridge.IncludeNulls := False;

    Result := TJSONObject.Create;
    Result.AddPair('DATA', lJSONBridge.Produce as TJSONValue);
  finally
    MyFDQuery.Active := False;
    lJSONBridge.Free;
  end;
end;

My problem is establishing a connection with a WEB CORE Bootstrap Client with the following code from the samples:

procedure TForm1.WebButton1Click(Sender: TObject);
begin
  XDataWebConnection1.URL := 'http://localhost:2001/tms/xdata/TestService/GetSampleData';
  try
    await(XDataWebConnection1.OpenAsync);
    WriteLn('XData server connected succesfully!');
  except
    on Error: Exception do
      ShowMessage('XData server connection failed with error: ' + Error.Message);
  end;
end;

The TXDataWebConnection seems to require a Model for the URL:
image

The Server function i have in mind wouldn´t always deliver the same Columns all the time so the model could change from request to request.

Is there a way to provide this model for a specified SQL? Or do you see any other way how i can make this work?

The model just describes the endpoints you have in your server.
Check your browser console and network tabs, my guess is that you are hitting a CORS issue. Try to add the CORS middleware to your XData server component.

Yes that seems to have been a Problem.

But i still can´t open the Connection because it´s trying to get http://localhost:2001/tms/xdata/TestService/GetSampleData/$model when i open the connection.

I can request the http://localhost:2001/tms/xdata/$model... Why is it trying to get the model for my function?

Because probably you configured TXDataWebConnection component wrongly. The URL you should put there is the root of your server (http://localhost:2001/tms/xdata), not the URL of your service, which I assumed you used.

That explains why the connection couldn´t connect. But where do i put my Service and entity then?

Can i even use the XDataWebConnection and XDataWebClient to get the Result of Service-Methods or can i only use it with the Aurelius Entities?

Sure, in the connection component you specify the root URL of the XData server. Then when using TXDataWebClient you specify the endpoint you want to connect to, either a CRUD endpoint or a service operation. It's described in the documentation:

https://doc.tmssoftware.com/biz/xdata/guide/web.html

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.