{ Invokable interfaces must derive from IInvokable }
IMyWeb = interface(IInvokable) //自定义的一个结构,继承自Iinvokable
['{E3070F4D-AEBF-47D6-963B-ADFFC4E7C7A1}'] //通过Ctrl+Shift+G生成的一个GUID
{ Methods of Invokable interface must not use the default }
{ calling convention; stdcall is recommended }
function gettext():widestring;stdcall;//自定义的一个方法,也是以后客户可以调用的方
end;
implementation
initialization
{ Invokable interfaces must be registered }
InvRegistry.RegisterInterface(TypeInfo(IMyWeb));//通过此方法来注册接
end.
第三步:实现第二步中所定义的接口和方法。先通过向导生成一个空的单元文件,然后定义自定义接口(IWebtest)的实现类。原代码如下:
实现接口代码
Java代码 收藏代码
{ Invokable implementation File for TMyWeb which implements IMyWeb }
第二步 编写客户程序:
第一步:新建一个Application。
第二步:File----->New----->Other------>WebServices----->Soap Services Importer
然后在Wsdl or Xml Schema Location中填入:.exe/wsdl/IMyWeb,然后确定即生成了一个新的接口定义单元。
生成的代码
Java代码 收藏代码
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://127.0.0.1:8090/cgi-bin/Project2.exe/wsdl/IMyWeb
// Encoding : utf-8
// Version : 1.0
// (2011-7-22 16:14:10 - 1.33.2.5)
// ************************************************************************ //
// ************************************************************************ //
// The following types, referred to in the WSDL document are not being represented
// in this file. They are either aliases[@] of other types represented or were referred
// to but never[!] declared in the document. The types from the latter category
// typically map to predefined/known XML or Borland types; however, they could also
// indicate incorrect WSDL documents that failed to declare or import a schema type.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema"
function GetIMyWeb(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): IMyWeb;
implementation
function GetIMyWeb(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): IMyWeb;
const
defWSDL = 'http://127.0.0.1:8090/cgi-bin/Project2.exe/wsdl/IMyWeb';
defURL = 'http://127.0.0.1:8090/cgi-bin/Project2.exe/soap/IMyWeb';
defSvc = 'IMyWebservice';
defPrt = 'IMyWebPort';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
Addr := defWSDL
else
Addr := defURL;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as IMyWeb);
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
finally
if (Result = nil) and (HTTPRIO = nil) then
RIO.Free;
end;
end;