Bookmarks:

type [ServiceContract] IMyService = interface(IInvokable) ['{BAD477A2-86EC-45B9-A1B1-C896C58DD5E0}'] function HelloWorld: string; function FindOverduePayments(CustomerId: integer): TList<TPayment>; end;

type [ServiceImplementation] TMyService = class(TInterfacedObject, IMyService) private function HelloWorld: string; function FindOverduePayments(CustomerId: integer): TList<TPayment>; end; implementation function TMyService.HelloWorld: string; begin Result := 'Hello, World'; end; function TMyService.FindOverduePayments(CustomerId: integer): TList<TPayment>; begin Result := TXDataOperationContext.Current.GetManager.Find<TPayment> .CreateAlias('Customer', 'c') .Where(TLinq.Eq('c.Id', CustomerId) and TLinq.LowerThan('DueDate', Now)) .List; end;

POST /tms/xdata/MyService/FindOverduePayments HTTP/1.1 { "CustomerId": 10 }

var Client: TXDataClient; MyService: IMyService; Payments: TList<TPayment>; begin Client := TXDataClient.Create; Client.Uri := 'http://myserver/tms/xdata'; MyService := Client.Service<IMyService>; Payments := MyService.FindOverduePayments(10); // add your logic that deals with TPayment objects end;

The latest TMS XData 1.1 version introduces a major feature: Service Operations . In addition to having your objects published as REST resources automatically, you can now add server-side logic in a very easy and straightforward way.Service operations are defined as interfaces. Any interface can become a set of operations, all you need to do is add the [ServiceContract] attribute to the interface:The next step is to write the server logic, which is done just by implementing the interface in some class, and adding the attribute [ServiceImplementation] to that class:The FindOverduePayments method implementation illustrates how smooth is the integration with TMS Aurelius. The TXDataOperationContext class provides you with some useful properties to implement your server logic. The main property is GetManager, which provides you with an Aurelius TObjectManager.All you have to do is use the manager to persist objects, or to query objects using the Aurelius full query API. When implementing the server logic, you don't have to deal with database connections (XData uses its connection pool), you don't need to instantiate the object manager, you don't need to deal with memory management and also with JSON serialization.To invoke the service operation from any client using HTTP, you just POST to the operation address, passing the parameters in JSON format:Another great thing is if your client is written in Dephi, you can use the TXDataClient class. You can then benefit from the interface you declared and use it at client side as well. Use the TXDataClient to retrieve the interface, and call the interface method. XData will do all the HTTP requesta and JSON conversion for you, and will give you the TPayment objects:You can learn more about XData using the official online documentation . Or you can refer directly to the Service Operations chapter.