I need to interact with a series of .Net web services. Currently about 150 people. Since delphi 2010 uses Thttprio to achieve this, I am trying to create a common proxy on the client side that can be called to create the corresponding soap service client. Does anyone know how I can pass an httprio object to a generic interface type?
thanks
Below is the proxy function I'm trying to use:
class function Web.Proxy<T>(svc: string): T; var HTTPRIO : THTTPRIO; begin HTTPRIO := THTTPRIO.Create(nil); HTTPRIO.URL := GetServiceURL(svc); Result:= HTTPRIO as T; //<-- Fails with "operator not applicable to this operand type" // Result:= T(HTTPRIO); //<-- also fails, but with "invalid typecast" end;
The idea is that I can call it the following:
Web.Proxy<AutmobileServiceSoap>('svc.asmx').GetAutomobile(125);
The WSDL import has an AutmobileServiceSoap, defined as follows:
AutmobileServiceSoap = interface(IInvokable)
And all wsdl imports has a function that returns an httprio object, in a similar way:
function GetAutomobileServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): AutomobileServiceSoap; const defWSDL = 'http://localhost:8732/Cars.Server/Data/AutomobileService.asmx?WSDL'; defURL = 'http://localhost:8732/Cars.Server/Data/AutomobileService.asmx'; defSvc = 'AutomobileService'; defPrt = 'AutomobileServiceSoap12'; 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 AutomobileServiceSoap); 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;
source share