13.13.2 Delphi Web Services样例程序
1.服务端
为了使读者朋友对Web Services程序的开发过程有一个较清晰的认识,这里作者用Delphi给大家做一个简单样例程序。服务端用来提供对外服务接口,只有服务端运行后,其提供的服务接口才能被其他应用所调用,这里我们把调用其服务接口的程序统一叫客户端。
首先,选择“SOAP Server Application”选项,如图13-110所示。
单击【OK】按钮,则弹出图13-111所示对话框信息,我们选择 “ISAPI/NSAPI Dynamic Link Library”,单击【OK】按钮,弹出确认对话框,如图13-112所示,单击【Yes】按钮。
图13-110 New Items对话框 图13-111 New SOAP Server Application对话框 图13-112 Confirm对话框
将出现图13-113所示界面信息,您可以在对话框中输入服务名称,这里我们将该服务接口定义为“MyHello”,单击【OK】按钮,将产生相关的单元(Unit)文件,下面将附上相关文件的源代码供大家参考。
图13-113 Confirm对话框 图13-114 WebModule1对话框(对应单元文件为main.pas)
main.pas源代码:
{ SOAP WebModule } unit main; interface uses SysUtils, Classes, HTTPApp, InvokeRegistry, WSDLIntf, TypInfo, WebServExp, WSDLBind, XMLSchema, WSDLPub, SOAPPasInv, SOAPHTTPPasInv, SOAPHTTPDisp, WebBrokerSOAP; type TWebModule1 = class(TWebModule) HTTPSoapDispatcher1: THTTPSoapDispatcher; HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker; WSDLHTMLPublish1: TWSDLHTMLPublish; procedure WebModule1DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); private { Private declarations } public { Public declarations } end; var WebModule1: TWebModule1; implementation {$R *.dfm} procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); begin WSDLHTMLPublish1.ServiceInfo(Sender, Request, Response, Handled); end; end. |