当前位置:网站首页>Delphi soap WebService server-side multiple soapdatamodules implement the same interface method, interface inheritance
Delphi soap WebService server-side multiple soapdatamodules implement the same interface method, interface inheritance
2022-07-04 21:34:00 【pcplayer】
scene
WebService Server side , For the convenience of code management , Different business logic , Get different TSoapDataModule Go inside . This is good for modular management of code .
Multiple TSoapDataModule You may need to implement the same interface method , Every TSoapDataModule The implementation code of the module for this method may be different ( Because the business is different ); The simplest possibility is that each module has different client access rights to check .
that , On the client side , Because it is the same method that calls different interfaces on the server , If you write a method call to each interface , Code redundancy .
terms of settlement
Server side : Server side interface , Default (IDE Auto generated code ) from IAppServerSOAP Inherit .
If I want multiple interfaces with the same method ( Or functions ), You can define an interface by yourself , from IAppServerSOAP Inherit .
All interfaces on the server side , Inherit from a parent interface . The same interface method as above , Declare to this parent interface .
In this way , The client only needs a method to call the parent interface , Depending on the subclass interface , The actual implementation module of the server is different . Get it done !
The following code passed the test .
Code - Server side interface declaration
IParientIntf = interface(IAppServerSOAP)
['{04E35D2B-4A63-45DE-98C0-AED830BB06B7}']
function Hello(const S: string): string; stdcall;
end;
//ISoapDM_A = interface(IAppServerSOAP)
ISoapDM_A = interface(IParientIntf)
['{4499D900-1856-4178-8D6E-617856DBE2BD}']
end;
//ISoapDM_B = interface(IAppServerSOAP)
ISoapDM_B = interface(IParientIntf)
['{9618B6D7-0826-47D7-AAF6-F7BB3D6F1CDE}']
end;
Server side , Code of module 1 :
TSoapDM_A = class(TSoapDataModule, ISoapDM_A, IAppServerSOAP, IAppServer)
FDConnection1: TFDConnection;
FDQuery1: TFDQuery;
DataSetProvider1: TDataSetProvider;
DataSetProvider11111: TDataSetProvider;
private
public
function Hello(const S: string): string; stdcall;
end;
function TSoapDM_A.Hello(const S: string): string;
begin
Result := 'Hello, ' + S + '; This is SoapDM_AAAAA';
end;
The service is end , Code of module 2 :
TSoapDM_B = class(TSoapDataModule, ISoapDM_B, IAppServerSOAP, IAppServer)
FDConnection1: TFDConnection;
FDQuery1: TFDQuery;
DataSetProvider1: TDataSetProvider;
DataSetProvider222222: TDataSetProvider;
private
public
function Hello(const S: string): string; stdcall;
end;
function TSoapDM_B.Hello(const S: string): string;
begin
Result := 'Hello, ' + S + '; This is SoapDM_B';
end;
Client code :
procedure TForm3.DoHello(Intf: IParientIntf; const S: string);
var
S2: string;
begin
S2 := Intf.Hello(S);
ShowMessage(S2);
end;
The client calls the server-side module 1 :
procedure TForm3.Button3Click(Sender: TObject);
begin
Self.DoHello(HttpRIO1 as ISoapDM_A, ' Hello ');
end;
The client calls the server-side module 2 :
procedure TForm3.Button2Click(Sender: TObject);
begin
Self.DoHello(HttpRIO2 as ISoapDM_B, ' Shenzhen ');
end;
Above call , Problems needing attention on the client :
The same HTTPRIO1 Called interface one , Then call interface 2 , There will be interface not support It's abnormal ; vice versa . Use the same HTTPRIO1 Call it successively 2 How to deal with different interfaces ? I haven't seen any method for the time being .
terms of settlement : Multiple HttpRIO example , Each instance corresponds to an interface .
therefore , In the above code , One is HttpRIO1 ; The other is HttpRIO2;
summary
Delphi Of WebService In the frame , The server side is made up of IDE Automatically created TSoapDataModule Subclass module of , Has its own interface declaration . This interface , Inherited from IAppServerSOAP;
We can declare an interface defined by ourselves , such as IParientIntf = interface(IAppServerSOAP)
Then manually modify IDE Created code , The inherited parent class of the interface of the module , Change it to IParientIntf;
In this way , It can simplify the code of the client , There is no need to correspond to each module , All implement the same calling code .
边栏推荐
- [ 每周译Go ] 《How to Code in Go》系列文章上线了!!
- 面试官:说说XSS攻击是什么?
- 杰理之AD 系列 MIDI 功能说明【篇】
- 插入排序,选择排序,冒泡排序
- Minidom module writes and parses XML
- Golang interview finishing three resumes how to write
- 数十亿公民信息遭泄漏!公有云上的数据安全还有“救”吗?
- Jerry's ad series MIDI function description [chapter]
- Routing configuration and connectivity test of Huawei simulator ENSP
- Flutter TextField示例
猜你喜欢
Explication détaillée du mécanisme de distribution des événements d'entrée multimodes
Shutter textfield example
杰理之增加进关机前把触摸模块关闭流程【篇】
maya灯建模
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
Can be displayed in CAD but not displayed in print
B站视频 声音很小——解决办法
华为ensp模拟器实现通信安全(交换机)
OMS系统实战的三两事
改善机器视觉系统的方法
随机推荐
Arcgis 10.2.2 | arcgis license server无法启动的解决办法
UTF encoding and character set in golang
torch.tensor和torch.Tensor的区别
How was MP3 born?
Shutter textfield example
Three or two things about the actual combat of OMS system
Nmap scan
杰理之AD 系列 MIDI 功能说明【篇】
redis03——Redis的网络配置与心跳机制
Learning breakout 3 - about energy
面试官:说说XSS攻击是什么?
Redis:Redis配置文件相关配置、Redis的持久化
华为模拟器ensp常用命令
改善机器视觉系统的方法
华为ensp模拟器实现通信安全(交换机)
解析steam教育中蕴含的众创空间
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
Poster cover of glacier
Kubedm initialization error: [error cri]: container runtime is not running
LambdaQueryWrapper用法