Proxy Server sample (Delphi)
Overview
This sample shows how to create a proxy server to redirect calls to another server without having to recreate the RODL file, thus allowing the use of the same types of the original server. This is a practical example of 3-tier architecture providing total control of any requests. As every call will pass from the proxy class before going to the real server, you can even stop methods from being dispatched any further.
ProxyServer_ProxyServer_Impl
was created by simply copying the original MainService_Impl.pas
file, renaming the TMainService
class to TProxyService
followed by implementing a bypass for all the method calls. This class is basically a server which accesses a RemObjects SDK server as a client would do.
Getting Started
- Launch both servers and run the client.
- The client allows you to select either server. When you execute a method using the Proxy Server, you will see both servers log the call.
Examine the Code
The server and the client are nothing special compared to other RO SDK applications. The only place you might want to look at is the proxy server service implementation part, to see how the call is passed through the proxy:
// Create the channel and message for communication with the server.
// You cannot use a persistent channel component because of access from multiple threads.
constructor TProxyService.Create;
begin
inherited;
fTCPChannel := TROIndyTCPChannel.Create(nil);
fBINMessage := TROBINMessage.Create(nil);
end;
function TProxyService.CreateService: IProxyServerMainService;
begin
result := CoProxyServerMainService.Create(fBINMessage, fTCPChannel);
end;
function TProxyService.Sum(const A: Integer; const B: Integer): Integer;
begin
// Create the service proxy instance and redirect the call
result := CreateService.Sum(A, B)
end;