Wednesday, October 14, 2009

DataSnap: In-Process Server Method

DataSnap Server Method was introduced in Delphi 2009. Most video or demo about DataSnap server method available only introduce socket based client server access communication. e.g.: TCP or HTTP protocol.
However, DataSnap was designed as a scalable data access solution that able to work with one, two, three or more tiers model. All examples we see so far are suitable for 2 or 3 tiers design. I can’t find any example talking about 1 tier or in-process design.
Indeed, it is very simple to work with in-process server method. Most steps are similar to out-of-process server methods.

Invoke the server method via in-process

You may see from the following code that there is no different to access the server method for in-process and out-of-process design.
First, you create an instant of datasnap server. This will register the DSServer to the TDBXDriverRegistry. e.g. DSServer1 in this case.
You may then use TSQLConnection with DSServer1 as driver name instead of “DataSnap” that require socket connection to initiate in-process communication invoking the server method.var o: TMyServerMethodDataModule; Q: TSQLConnection; c: TMyServerMethodClient; begin o := TMyServerMethodDataModule.Create(Self); Q := TSQLConnection.Create(Self); try Q.DriverName := 'DSServer1'; Q.LoginPrompt := False; Q.Open; c := TMyServerMethodClient.Create(Q.DBXConnection); try ShowMessage(c.EchoString('Hello')); finally c.Free; end; finally o.Free; Q.Free; end; end;

4 comments:

Thanks, I missed that part in all the Datasnap articles I readed...Did you ever tried with a TDataSet as the result of a ServerMethode?I get an access violation when accessing dataset.Fields[i].Value, dataset.Fields[i].Fullname gives me the correct fieldname.