You are not logged in.
Can you show me a piece of more efficient code? I suspect that you have a better approach ![]()
Thank you. It's working now.
I have a new question: need to send a image (.jpg or .tiff, size from 2mb to 5mb) from server to client. I'm thinking about write a remote method that returns a sort of blob, but don't know which type use:
type
IPictureService = interface(IInvokable)
['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
function GetPicture(Index: Integer): <which type? TDynArray? Don't know>;
end;EDIT: I found a solution. Return a record. It's the best approach?
Interface
type
TPicturePackage = record
FileName: RawUTF8;
Binary: TByteDynArray;
end;
IPictureService = interface(IInvokable)
['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
function GetPicture(Index: Integer): TPicturePackage;
end;Server:
function TPictureService.GetPicture(Index: Integer): TPicturePackage;
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
try
Result.FileName := 'biology' + IntToStr(Index) + '.jpg';
Stream.LoadFromFile(Result.FileName);
SetLength(Result.Binary, Stream.Size);
Move(Stream.Memory^, Result.Binary[0], Stream.Size);
finally
Stream.Free;
end;
end;Client:
Package := PictureService.GetPicture(1);
Stream := TMemoryStream.Create;
try
Stream.Size := Length(Package.Binary);
Move(Package.Binary[0], Stream.Memory^, Stream.Size);
Stream.SaveToFile(Package.FileName);
finally
Stream.Free;
end;Hi.
I need to know the client's IP address. Where to look for?
Thank you.
Maybe there are a bug when the return value of a interface based method is a Boolean.
SynCommons.JSONDecode() thinks that a correct value from server is invalid and gives me a exception "Error calling MyBooleanTest.Test remote method".
Interface:
type
IMyBooleanTest = interface(IInvokable)
['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
function Test: Boolean;
end;
const
ROOT_NAME = 'root';
APPLICATION_NAME = 'RestService';Server.dpr:
type
TMyBooleanTest = class(TInterfacedObject, IMyBooleanTest)
public
function Test: Boolean;
end;
function TMyBooleanTest.Test: Boolean;
begin
Result := False;
end;
var
aModel: TSQLModel;
aServer: TSQLRestServer;
aHTTPServer: TSQLite3HttpServer;
begin
aModel := TSQLModel.Create([],ROOT_NAME);
try
aServer := TSQLRestServerFullMemory.Create(aModel,'test.json',false,true);
try
aServer.ServiceRegister(TMyBooleanTest,[TypeInfo(IMyBooleanTest)],sicShared);
aHTTPServer := TSQLite3HttpServer.Create('888',[aServer]);
try
writeln('Background server is running.'#10);
write('Press [Enter] to close the server.');
readln;
finally
aHTTPServer.Free;
end;
finally
aServer.Free;
end;
finally
aModel.Free;
end;
end.Client:
procedure TForm1.btnCallClick(Sender: TObject);
var
MyTest: IMyBooleanTest;
begin
if Client=nil then begin
if Model=nil then
Model := TSQLModel.Create([],ROOT_NAME);
Client := TSQLite3HttpClient.Create('localhost','888',Model);
Client.SetUser('User','synopse');
Client.ServiceRegister([TypeInfo(IMyBooleanTest)],sicShared);
end;
if Client.Services['MyBooleanTest'].Get(MyTest) then
ShowMessage(BoolToStr(MyTest.Test)); // <- "Error calling MyBooleanTest.Test remote method".
end;Some years ago, I have created a web service (SOAP) in Ruby on Rails 1.1. It works but I want to replace it.
But we have now many deployed Delphi 7 applications using this service. Therefore I can't change the SOAP protocol right now.
I'm thinking about write a mORMot server to accept SOAP as input and return SOAP as output. Then I will extend this service with more interface based features.
Do you think this is a viable approach? The ruby web service have only one method. Any hints?
I was thinking about using high performance messages from ZeroMQ open source library to make a publisher/subscriber. If it works then will be a good approach to receive notifications from server.
What you think?
Now it's working. Thank you.
By the way, named pipes can be used in a local network or http is the only solution?
I have tried your sample and it worked. But I don't know how to rewrite your sample code to work using http.
When I try, client give me a exception '"Calculator" interface or REST routing not supported by server:'
What I am doing wrong?
Can you please write a http version of your sample '14 - Interface based services'? Thank you very much.
PS: I never tried synopse mORMot before, but it seems easier to comunicate with server using mORMot than using DataSnap or Asta. Better than a webservice too. Great work.
Hello.
I am thinking about use togheter this two great Delphi frameworks: Unigui, the best UI for the web plus SQLite3 framework.
I have created some applications using unigui (www.unigui.com) with great success, but don't want use TDataSet anymore. How can I use SQLite3 + Unigui?
It is a viable approach?