编写一个单独的Web Service for Delphi7(步骤)

早段时间看了一篇好文章,对其整理成以下几步

1新建一个SOAP Server Application,在提示输入接口时输入MyHello,把所有文件
保存在一个叫Ser的目录下,其中一个包含TWebModule1的文件保存为main.pas.
在MyHelloIntf.pas的IMyHello接口中加入
function Welcome(name:string):string;stdcall;

在MyHelloImpl.pas中的TMyHello实现此方法
function TMyHello.Welcome(name:string):string;
begin
result:='Welcome '+name;
end;

2新建一个标准Application,把所有文件保存在刚才哪个Ser目录下(同一目录).
文件名默认,在Unit1.pas中Uese IdHTTPWebBrokerBridge,可能还要在工程
的Search path加入

 1<delphi7>\Source\Indy <delphi7>是Delphi的安装目录   
 23在form1上放一个lable,写上"Stand Alone Web Service"   
 34在TForm1的private中加入一个变量ser:TIdHTTPWebBrokerBridge;   
 45Uses第一步中的main.pas MyHelloIntf.pas MyHelloImpl.pas   
 57在OnFormCreate事件上写   
 6ser:=TIdHTTPWebBrokerBridge.Create(self);   
 7ser.DefaultPort:=5678;   
 8ser.Active:=true;   
 9ser.RegisterWebModuleClass(TWebModule1);   
108运行程序,打开IE,输入http://localhost:5678/.结果大家都想到了   
11  
12写Client   
131关闭所有文件.   
142新建一个标准Application   
153运行刚才写的服务器Application   
164运行wsdl import wizard,在URL中输入http://localhost:5678/wsdl/IMyHello   
17按Next几次   
185保存所有文件到一个新目录,用Wizard产生的文件保存为IMyHello1.pas,其余默认,在Unit1.pas中uses   
19  
20IMyHello1.pas,放一个TButton,写上下面的代码,运行.   
21procedure TForm1.Button1Click(Sender: TObject);   
22var   
23I:IMyHello;   
24begin   
25I:=GetIMyHello;   
26ShowMessage(I.Welcome('black man'));   
27I:=nil;   
28end;</delphi7></delphi7>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus