当前位置:网站首页>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 .
边栏推荐
- 2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
- Minidom module writes and parses XML
- 【活动早知道】LiveVideoStack近期活动一览
- Huawei simulator ENSP common commands
- redis03——Redis的网络配置与心跳机制
- [weekly translation go] how to code in go series articles are online!!
- Render function and virtual DOM
- 每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation
- Monitor the shuttle return button
- The video sound of station B is very low - solution
猜你喜欢
Huawei ENSP simulator enables devices of multiple routers to access each other
数十亿公民信息遭泄漏!公有云上的数据安全还有“救”吗?
Jerry's ad series MIDI function description [chapter]
【C語言】符號的深度理解
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
B站视频 声音很小——解决办法
搭建一个仪式感点满的网站,并内网穿透发布到公网 1/2
Arcgis 10.2.2 | arcgis license server无法启动的解决办法
杰理之AD 系列 MIDI 功能说明【篇】
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
随机推荐
Poster cover of glacier
Day24: file system
Embedded TC test case
【C語言】符號的深度理解
maya灯建模
PS vertical English and digital text how to change direction (vertical display)
华为ensp模拟器 配置ACL访问控制列表
y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
Learning breakout 3 - about energy
Day24:文件系统
刘锦程荣获2022年度中国电商行业创新人物奖
minidom 模块写入和解析 XML
Jerry added the process of turning off the touch module before turning it off [chapter]
Daily question -leetcode1200- minimum absolute difference - array - sort
杰理之AD 系列 MIDI 功能说明【篇】
华为ensp模拟器 实现多个路由器的设备可以相互访问
Shutter textfield example
Flutter TextField示例
Flutter在 release版本,打开后随机白屏不显示内容
Difference between ApplicationContext and beanfactory (MS)