当前位置:网站首页>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 .
边栏推荐
- Solution of 5g unstable 5g signal often dropped in NetWare r7000 Merlin system
- 【optimtool.unconstrain】无约束优化工具箱
- Huawei ENSP simulator layer 3 switch
- 应用实践 | 蜀海供应链基于 Apache Doris 的数据中台建设
- Daily question-leetcode556-next larger element iii-string-double pointer-next_ permutation
- 面试官:说说XSS攻击是什么?
- 搭建一个仪式感点满的网站,并内网穿透发布到公网 1/2
- c语言函数形参自增自减情况分析
- shp数据制作3DTiles白膜
- IIC (STM32)
猜你喜欢

解析steam教育中蕴含的众创空间

Huawei ENSP simulator configures DHCP for router

【活动早知道】LiveVideoStack近期活动一览

【optimtool.unconstrain】无约束优化工具箱

shp数据制作3DTiles白膜
![Compréhension approfondie du symbole [langue C]](/img/4b/26cf10baa29eeff08101dcbbb673a2.png)
Compréhension approfondie du symbole [langue C]

UTF encoding and character set in golang

The video sound of station B is very low - solution

MP3是如何诞生的?

解析互联网时代的创客教育技术
随机推荐
华为模拟器ensp常用命令
Numpy vstack and column_ stack
Golang interview finishing three resumes how to write
ApplicationContext 与 BeanFactory 区别(MS)
PS vertical English and digital text how to change direction (vertical display)
Jerry's ad series MIDI function description [chapter]
redis RDB AOF
flink1.13 sql基础语法(一)DDL、DML
华为ensp模拟器 配置ACL访问控制列表
Jerry's ad series MIDI function description [chapter]
Can be displayed in CAD but not displayed in print
Redis bloom filter
Roast B station charges, is it because it has no money?
Foxit pdf editor v10.1.8 green version
创客思维在高等教育中的启迪作用
redis管道
c语言函数形参自增自减情况分析
解析互联网时代的创客教育技术
2021 CCPC Harbin I. power and zero (binary + thinking)
杰理之AD 系列 MIDI 功能说明【篇】