在运行注册DataSnap服务器类时发布provider
来源:互联网 发布:淘宝宝贝怎么被删除了 编辑:程序博客网 时间:2024/06/05 21:56
A while ago I published a blog post about How to register DataSnap Server Class in runtime with Delphi, after that I got some feedback mentioning the source code I provided just publishes the Server Methods, and not the Providers as part of the Server Module, in other words the client application couldn’t see the Providers available on the DataSnap Server.
The solution for this issue is very simple, we just need to register the TDSProviderDataModuleAdapter class, which is used internally to allow a TProviderDataModule to be exposed to DataSnap clients. TDSProviderDataModuleAdapter acts as a proxy between a server-side TProviderDataModule and client-sides TDSProviderConnection.
We could just update the GetDSClass method implementation as below, it works, but it would not be the best implementation, just because the following code will always publish the IAppServer interface methods to the client side, in case your ServerModule doesn’t have any Provider, why you will publish the IAppServer? Doesn’t make sense, right?
Making the publication parameterizable will bring more flexibility and control to the application and the developer, it will be your decision to publish the Providers or not. A new parameter in the TSimpleServerClass constructor is everything we need.
function TSimpleServerClass.GetDSClass: TDSClass;
1
begin
2
Result := TDSClass
.
Create(FPersistentClass,
False
);
3
Result := TDSClass
.
Create(TDSProviderDataModuleAdapter, Result)
4
end
;
The following code represents the new implementation for the TSimpleServerClass. The change adds a new parameter (ExposeProvider) to the constructor, which will allow the developer to publish the providers (or not).
01
type
02
03
unit
SimpleServerClass;
04
05
interface
06
07
uses
DSServer, Classes, DSCommonServer, DSReflect;
08
09
type
10
11
TSimpleServerClass =
class
(TDSServerClass)
12
private
13
FPersistentClass: TPersistentClass;
14
FExposeProvider :
Boolean
;
15
protected
16
function
GetDSClass: TDSClass; override;
17
public
18
constructor
Create(AOwner: TComponent; AServer: TDSCustomServer;
19
AClass: TPersistentClass; ExposeProvider:
Boolean
; ALifeCycle:
String
);
20
reintroduce; overload;
21
end
;
22
23
implementation
24
25
constructor
TSimpleServerClass
.
Create(AOwner: TComponent;
26
AServer: TDSCustomServer; AClass: TPersistentClass; ExposeProvider:
Boolean
;
27
ALifeCycle:
String
);
28
begin
29
inherited
Create(AOwner);
30
FPersistentClass := AClass;
31
FExposeProvider := ExposeProvider;
32
Self
.
Server := AServer;
33
Self
.
LifeCycle := ALifeCycle;
34
35
end
;
36
37
function
TSimpleServerClass
.
GetDSClass: TDSClass;
38
var
39
isAdapted :
Boolean
;
40
begin
41
isAdapted := FPersistentClass
.
InheritsFrom(TProviderDataModule);
42
Result := TDSClass
.
Create(FPersistentClass, isAdapted);
43
if
FExposeProvider
and
isAdapted
then
44
Result := TDSClass
.
Create(TDSProviderDataModuleAdapter, Result)
45
end
;
46
47
end
.
The following code registers 3 classes, where only one exposes the Providers:
1
procedure
RegisterServerClasses(AOwner: TComponent; AServer: TDSServer);
2
begin
3
Assert(AServer
.
Started =
false
,
'Can'
't add class to non active Server'
);
4
5
TSimpleServerClass
.
Create(AOwner, AServer, TGlobal,
False
, TDSLifeCycle
.
Server);
6
TSimpleServerClass
.
Create(AOwner, AServer, TCustomer,
True
, TDSLifeCycle
.
Session);
7
TSimpleServerClass
.
Create(AOwner, AServer, TObjectPool,
False
, TDSLifeCycle
.
Invocation);
8
end
;
- 在运行注册DataSnap服务器类时发布provider
- Delphi在运行时注册Datasnap服务类
- datasnap——动态注册服务类 datasnap——动态注册服务类 在DataSnap的应用程序时,我们首先需要注册的服务器类,以提供访问客户端应用程序的服务器方法。通常的做法是使用DSSer
- 在Datasnap服务端动态注册类
- 如何在运行时改变User Profile的Provider
- 开发DataSnap服务器
- 在从服务器接收结果时发生传输级错误。 (provider: Shared Memory Provider, error: 0 - 句柄无效。)
- vs2010+SQL2008R2在本地发布成的网站,如何在服务器上配置环境与运行?
- 如何使程序在运行时自动注册ActiveX控件
- 如何使程序在运行时自动注册ActiveX控件
- 如何使程序在运行时自动注册ActiveX控件
- 在程序运行时自动注册ActiveX控件
- 不通过web.config在运行时注册httpmodules
- 利用DataSnap的回调功能在客户端显示服务器方法的执行进度
- DataSnap服务端和客户端发布分发方法
- DataSnap
- 如何注册程序在指定时间运行
- 运行时发布
- addslashes()和addclashes()函数的区别和比较。
- (转)Ws2tcpip.h
- android popwindow 解决opengl层叠上面的ui被覆盖的现象
- Runtime.getRuntime()
- 配置V0.8_概述及目录
- 在运行注册DataSnap服务器类时发布provider
- ATL布幔下的秘密之窗口类的秘密
- curl: (6) Couldn't resolve host 'android.git.kernel.org'
- C开发环境的数据长度
- Android Dialog 设置透明
- C#实现图片翻转
- Wifi学习
- (转)再谈突破TCP-IP过滤/防火墙进入内网(icmp篇)
- HTML5 GAME West Fighting / 西途决斗 框架说明