Missing service implementation for controller

Hi!

I am developing an XData server with Service operations. Here's some code that describes the

Interface definition:

unit Admin.Service.Intf;

interface

uses
  System.Classes,
  Generics.Collections,
  XData.Service.Common,
  Aurelius.Criteria.Base,
  XData.Security.Attributes,
  Aurelius.Mapping.Attributes,
  Entities.Admin;

type
  [ServiceContract]
  [Model('admin')]

  IAdminService = interface(IInvokable)
    ['{4B3C6BEF-2022-4607-9EF2-81FDCB10C51B}']
    ...
    [HttpGet] function StartEnvironment(EnvId: integer): boolean;
  end;

implementation

initialization
  RegisterServiceType(TypeInfo(IAdminService));

end.

Implementation:

unit Admin.Service;

interface

uses
  System.SysUtils, System.Classes, Generics.Collections, XData.Service.Common,
  Entities.Admin, Aurelius.Engine.ObjectManager, Bcl.Jose.Core.JWT, Bcl.Jose.Core.Builder,
  Sparkle.Security, XData.Sys.Exceptions, XData.Security.Attributes, LoggerProxy,

  FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error,
  FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool,
  FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef,
  FireDAC.VCLUI.Wait, FireDAC.Comp.Client, Aurelius.Linq, Aurelius.Criteria.Linq,
  Aurelius.Criteria.Base, XData.Server.Module, Aurelius.Engine.DatabaseManager,

  Admin.Service.Intf
  ;

type
  [ServiceImplementation]
  TAdminService = class(TInterfacedObject, IAdminService)
  private
    ...
    function StartEnvironment(EnvId: integer): boolean;
  end;

function TAdminService.StartEnvironment(EnvId: integer): boolean;
begin
  var mngr := TXDATAOperationContext.Current.GetManager;

  var env := mngr.Find<TEnvironment>(EnvId);

  ServerContainer.StartEnvironment(env);
end;

The code compiles and executes well. I open the Swagger UI and after executing the StartEnvironment method I get the exception

Project EasyServer.Vcl.exe raised exception class 
EXDataHttpMissingServiceImplementation with message 
'Missing service implementation for controller "AdminService"'.

None of the service operations works. I rechecked the thing many times and can't find where I made a mistake.

Any advice would be a great start here :slight_smile:

did you register the implementation? Safest way to create a service is using the service wizard in New |Other | XData

did you register the implementation? Safest way to create a service is using the service wizard in New |Other | XData

I have this on the interface unit

initialization
  RegisterServiceType(TypeInfo(IAdminService));

[/quote]

and this on the service implementation

initialization
  RegisterServiceType(TEasyService);

Is anything else I need to check about registration?

Have you tried adding

  [Model('admin')]

attribute to the TAdminService class?

(post deleted by author)

Yes, I added also on the implementation, but no luck. I tried to compare it with TAdminLoginService (that is working), but found no differences.

Found!

The code

initialization
  RegisterServiceType(TAdminService);

was after the last "end." so it was ignored by the code. I apologize form my stupid mistake.

1 Like