Accessing a service from Desktop App

I have a Service defined as

  [ServiceContract]
  [Model('Biz.Sphinx')]
  IGARegisterService = interface(IInvokable)
    ['{D1A8DFD7-C32F-4E05-8395-A1484201FE74}']
    [HttpGet]
    function Hello: String;
 end;

From a WebCore app I can access this service with

lRetval := await(TXDataClientResponse, WebClient.RawInvokeAsync('IGARegisterService.Hello', []));

WebClient is a TXDataWebClient linked to a TXDataWebConnection that uses the url http://127.0.0.1:2018/GASphinx

However in a VCL desktop application I have

var
  Client: TXDataClient;
  Retval: string;
begin
   Client := TXDataClient.Create;
  try
    Client.Uri := 'http://127.0.0.1:2018/GASphinx';
    try

      Retval := Client.Service<IGARegisterService>.Hello;
      MessageDlg(Retval, mtInformation, [mbOK], 0);
    except
      on e: exception do
         MessageDlg(e.Message, mtError, [mbOK], 0);
    end;
  finally
    Client.Free;
  end;
end;

But this raises the exception:

Project GATools.exe raised exception class EXDataInterfaceServiceNotFound with message 'Interface "IGARegisterService" not registered as a service contract.'.

Obviously I'm missing something somewhere.

Any ideas? Thanks.

Since your interface is tagged to model Biz.Sphinx, you should create the TXDataClient for that model:

   Client := TXDataClient.Create(TXDataAureliusModel.Get('Biz.Sphinx');

But Biz.Sphinx is an internal model used by TMS Sphinx, so I simply recommend that you remove the Model attribute from your interface, or simply use a different model.

Thanks.

I have it marked as Biz.Sphinx as I was having issues when I had it unmarked or marked as a different model.

What kind of issues? Note that when updating the database structure, you can pass several model names so the database will be updated accordingly to hold tables for all the provided models.

If I remove the service from Biz.Sphinx then I can't access it through the url that is used to access Sphinx.

If I add another XData server to the server app with a different URL then I can access the service, but then I get

Project GASphinx.exe raised exception class EXDataMissingConnection with message 'Database connection not avaiable. Check if the connection pool is properly configured.'.

Then records I am adding/updating are in the Biz.Sphinx model (extended user class and an organisation/company class).

Correct, you need another XData server.

That simply means you should set the Pool property of the TXDataServer component, if you want to use databases.

But fine, if you are extending Sphinx and all this is related to Sphinx, it's no problem you use the model Biz.Sphinx. But then, as I said, create the TXDataClient using that model.

1 Like

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