#201 Re: mORMot 1 » Interface based services » 2012-03-23 21:01:38

Can you show me a piece of more efficient code? I suspect that you have a better approach smile

#202 Re: mORMot 1 » Interface based services » 2012-03-23 18:19:44

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;

#203 mORMot 1 » How to get the client's IP address? » 2012-03-22 15:38:49

Junior/RO
Replies: 5

Hi.

I need to know the client's IP address. Where to look for?

Thank you.

#204 Re: mORMot 1 » Interface based services » 2012-03-21 16:30:05

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;

#205 mORMot 1 » Replacing a SOAP webservice with mORMot » 2012-03-15 15:43:17

Junior/RO
Replies: 1

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?

#206 mORMot 1 » ZeroMQ broadcasting » 2012-03-12 22:26:40

Junior/RO
Replies: 1

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?

http://www.zeromq.org/

#207 Re: mORMot 1 » Interface based services » 2012-03-12 22:10:23

Now it's working. Thank you.

By the way, named pipes can be used in a local network or http is the only solution?

#208 Re: mORMot 1 » Interface based services » 2012-03-12 13:31:37

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.

#209 mORMot 1 » Using SQLite3 Framework with Unigui Framework » 2011-05-13 00:30:24

Junior/RO
Replies: 1

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?

Board footer

Powered by FluxBB