TSOAPClient - Exemples

TSOAPClient = class (TObject)Interface de TSOAPClientExemples de TSOAPClient

Exemple d'utilisation d'un service SOAP :

function SoapCall(sc : TSOAPClient ; const serviceName, bindingName, methodName, paramsAsCommaText : String) : String;
begin
   var req := sc.SoapRequestAsXML(serviceName, bindingName, methodName, paramsAsCommaText);
   var resp := sc.SoapInvoke(serviceName, bindingName, methodName, req);
   Result := sc.DecodeSoapResponseAsCommaText(serviceName, bindingName, methodName, resp);
end;

var cacheWSDL := ReadGlobalVar('CacheWSDL');

var sc := TSOAPClient.Create;
if cacheWSDL = '' then begin
   sc.WSDLURL := 'http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL';
   WriteGlobalVar('CacheWSDL', sc.WSDL, 300);
end else
   sc.WSDL := cacheWSDL;

var serviceName := 'CountryInfoService';
var bindingName := 'CountryInfoServiceSoapBinding';
PrintLn(SoapCall(sc, serviceName, bindingName, 'CountryName', 'CountryName.sCountryISOCode=FR'));
PrintLn(SoapCall(sc, serviceName, bindingName, 'FullCountryInfoAllCountries', ''));
PrintLn(SoapCall(sc, serviceName, bindingName, 'FullCountryInfo', 'FullCountryInfo.sCountryISOCode=FR'));

Exemple d'appel en script d'un service Soap publié par un WebProcess Qubes :

function WebServiceSoap(urlQuBESExpress, webProcessRUD, methodName : String ;
                        parameters : TStrings ;
                        timeOut: Integer = 30) : String;
begin
   var soapClient := new TSOAPClient;
   var connectionURL := urlQuBESExpress+'WebProcess.cit/'+webProcessRUD+'/';
   soapClient.DownloadTimeOut := timeOut*1000;
   soapClient.IgnoreProxy := True;
   soapClient.ServiceURL := connectionURL;
   soapClient.WSDLURL := connectionURL;
   if Pos(methodName, soapClient.WSDL) = 0 then
      raise Exception.Create('Methode non publiée par le WebService');

   var serviceName := 'SOAPPublisher';
   var bindingName := 'SOAPPublisherSoap';
   var params := new TStrings;
   params.CommaText := soapClient.ParamNamesAsCommaText(serviceName, bindingName, methodName);
   if(params.Count <> parameters.Count) then
      raise Exception.Create('Nombre de paramètres incorrect');
   for var i := 0 to params.Count-1 do
      params[i] := params[i] + '=' + parameters[i];

   var soapRequestInXml := soapClient.SoapRequestAsXML(serviceName, bindingName, methodName, params.CommaText);
   var soapResponseInXml := soapClient.SoapInvoke(serviceName, bindingName, methodName, soapRequestInXml);
   Result := soapClient.DecodeSoapResponseAsCommaText(serviceName, bindingName, methodName, soapResponseInXml);
end;