同样还是调用昨晚的libss.dll。
1. 新建个Console Application,叫SampleService.Invoker。
2. File->New->Other, Web Services\WSDL Importer,在Location of WSDL File or URL处填上http: //localhost/MyServices/SampleService/libss.dll/wsdl/ISampleService,然后点击 Finish,然后再点击Finish,接着把生成的单元保存成IComplexOperatorsUnit.pas。
下面是生成的单元的内容:
//************************************************************************//
//Thetypesdeclaredinthisfileweregeneratedfromdatareadfromthe
//WSDLFiledescribedbelow:
//WSDL:http://localhost/MyServices/SampleService/libss.dll/wsdl/ISampleService
//Encoding:utf-8
//Version:1.0
//(2006-9-2910:03:31-16.03.2006)
//************************************************************************//
unitISampleServiceUnit;
interface
usesInvokeRegistry,SOAPHTTPClient,Types,XSBuiltIns;
type
//************************************************************************//
//Thefollowingtypes,referredtointheWSDLdocumentarenotbeingredivsented
//inthisfile.Theyareeitheraliases[@]ofothertypesredivsentedorwerereferred
//tobutnever[!]declaredinthedocument.Thetypesfromthelattercategory
//typicallymaptodivdefined/knownXMLorBorlandtypes;however,theycouldalso
//indicateincorrectWSDLdocumentsthatfailedtodeclareorimportaschematype.
//************************************************************************//
//!:double-"http://www.w3.org/2001/XMLSchema"
//!:int-"http://www.w3.org/2001/XMLSchema"
//[WARNINGS]**************************************************************//
//Unabletosorttype'TClassA'duetocircularreference!
//************************************************************************//
TComplex=class;{"urn:SampleServiceIntf"}
TExtraData=class;{"urn:SampleServiceIntf"}
TLoopable=class;{"urn:SampleServiceIntf"}
TClassA=class;{"urn:SampleServiceIntf"}
TClassB=class;{"urn:SampleServiceIntf"}
//************************************************************************//
//Namespace:urn:SampleServiceIntf
//************************************************************************//
TComplex=class(TRemotable)
private
FR:Double;
FI:Double;
published
propertyR:DoublereadFRwriteFR;
propertyI:DoublereadFIwriteFI;
end;
//************************************************************************//
//Namespace:urn:SampleServiceIntf
//************************************************************************//
TExtraData=class(TRemotable)
private
FX:Integer;
published
propertyX:IntegerreadFXwriteFX;
end;
//************************************************************************//
//Namespace:urn:SampleServiceIntf
//************************************************************************//
TLoopable=class(TRemotable)
private
FData:TExtraData;
FNext:TLoopable;
public
destructorDestroy;override;
published
propertyData:TExtraDatareadFDatawriteFData;
propertyNext:TLoopablereadFNextwriteFNext;
end;
//************************************************************************//
//Namespace:urn:SampleServiceIntf
//************************************************************************//
TClassA=class(TRemotable)
private
Fref:TClassB;
public
destructorDestroy;override;
published
propertyref:TClassBreadFrefwriteFref;
end;
//************************************************************************//
//Namespace:urn:SampleServiceIntf
//************************************************************************//
TClassB=class(TRemotable)
private
Fref:TClassA;
public
destructorDestroy;override;
published
propertyref:TClassAreadFrefwriteFref;
end;
//************************************************************************//
//Namespace:urn:SampleServiceIntf-ISampleService
//soapAction:urn:SampleServiceIntf-ISampleService#operationName
//transport:http://schemas.xmlsoap.org/soap/http
//style:rpc
//binding:ISampleServicebinding
//service:ISampleServiceservice
//port:ISampleServicePort
//URL:http://localhost/MyServices/SampleService/libss.dll/soap/ISampleService
//************************************************************************//
ISampleService=interface(IInvokable)
['{A454ABF4-3610-70C0-E88F-F2F022F2A747}']
functionComplexAdd(consta:TComplex;constb:TComplex):TComplex;stdcall;
functionLoop(constLevel:Integer):TLoopable;stdcall;
functionGetClassAB:TClassA;stdcall;
end;
functionGetISampleService(UseWSDL:Boolean=System.False;Addr:string='';HTTPRIO:THTTPRIO=nil):ISampleService;
implementation
functionGetISampleService(UseWSDL:Boolean;Addr:string;HTTPRIO:THTTPRIO):ISampleService;
const
defWSDL='http://localhost/MyServices/SampleService/libss.dll/wsdl/ISampleService';
defURL='http://localhost/MyServices/SampleService/libss.dll/soap/ISampleService';
defSvc='ISampleServiceservice';
defPrt='ISampleServicePort';
var
RIO:THTTPRIO;
begin
Result:=nil;
if(Addr='')then
begin
ifUseWSDLthen
Addr:=defWSDL
else
Addr:=defURL;
end;
ifHTTPRIO=nilthen
RIO:=THTTPRIO.Create(nil)
else
RIO:=HTTPRIO;
try
Result:=(RIOasISampleService);
ifUseWSDLthen
begin
RIO.WSDLLocation:=Addr;
RIO.Service:=defSvc;
RIO.Port:=defPrt;
endelse
RIO.URL:=Addr;
finally
if(Result=nil)and(HTTPRIO=nil)then
RIO.Free;
end;
end;
destructorTLoopable.Destroy;
begin
ifAssigned(FData)then
FData.Free;
ifAssigned(FNext)then
FNext.Free;
inheritedDestroy;
end;
destructorTClassA.Destroy;
begin
ifAssigned(Fref)then
Fref.Free;
inheritedDestroy;
end;
destructorTClassB.Destroy;
begin
ifAssigned(Fref)then
Fref.Free;
inheritedDestroy;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(ISampleService),'urn:SampleServiceIntf-ISampleService','utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ISampleService),'urn:SampleServiceIntf-ISampleService#operationName');
RemCla***egistry.RegisterXSClass(TComplex,'urn:SampleServiceIntf','TComplex');
RemCla***egistry.RegisterXSClass(TExtraData,'urn:SampleServiceIntf','TExtraData');
RemCla***egistry.RegisterXSClass(TLoopable,'urn:SampleServiceIntf','TLoopable');
RemCla***egistry.RegisterXSClass(TClassA,'urn:SampleServiceIntf','TClassA');
RemCla***egistry.RegisterXSClass(TClassB,'urn:SampleServiceIntf','TClassB');
end.
注意上面的destructors!
把TClassB.Destroy改成这样:
destructorTClassB.Destroy;
begin
inheritedDestroy;
end;
转载于:https://blog.51cto.com/rosehacker/450167