一、Delphi中编写Web Service的步骤如下:
1. File->New->other;
2. 在打开的对话框中,选择Web Services->SOAP Server Application
3. 选择ISAPI DLL
4. 选择Yes,自动生成接口和实现文件
也可以选择No,可以使用SOAP Server Interface向导来添加接口:
5. 输入接口名称
输入名称XXX后,会自动生成XXXIntf.pas和XXXImpl.pas文件,分别对应接口和类的实现。
二、代码范例
1. XXXIntf.pas
{ Invokable interface ISampleService }
unit SampleServiceIntf;
interface
uses InvokeRegistry, Types, XSBuiltIns;
type
{ Invokable interfaces must derive from IInvokable }
ISampleService = interface(IInvokable)
['{FD7D3BA8-8FE8-47F7-8A06-08A8663A4FF3}']
{ Methods of Invokable interface must not use the default }
{ calling convention; stdcall is recommended }
end;
implementation
initialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(ISampleService));
end.
2. XXXImpl.pas
{ Invokable implementation File for TSampleService which implements ISampleService }
unit SampleServiceImpl;
interface
uses InvokeRegistry, Types, XSBuiltIns, SampleServiceIntf;
type
{ TSampleService }
TSampleService = class(TInvokableClass, ISampleService)
public
end;
implementation
initialization
{ Invokable classes must be registered }
InvRegistry.RegisterInvokableClass(TSampleService);
end.