PDA

Ver la Versión Completa : Autenticacion-soapheader


moran.j.e
14-07-2012, 17:09:17
Hola a todos, estoy iniciandome en el desarrollo sobre delphi, no tengo mucha experiencia,y en el trabajo se me pidio que realice una conexión con un webservice ya existente "libro de quejas punto com".
Mi principal problema pasa por la autenticación HTTP, no se como construir la cabecera que contiene los datos de autenticación. A mi para realizar esta conexión se me dio "h..p://app.librodequejas.com/1/ws.php?wsdl" y lo que hago es crear un WSDL importer, el cual me crea la siguiente interfaz.

unit ws1;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

type

LDQ___Application_ServicesPortType = interface(IInvokable)
['{258099E3-2F62-F229-1C66-7114AF03208D}']
function listComplaints(const q: WideString; const id: integer): WideString; stdcall;
end;

function GetLDQ___Application_ServicesPortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): LDQ___Application_ServicesPortType;


implementation

function GetLDQ___Application_ServicesPortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): LDQ___Application_ServicesPortType;
const
defWSDL = 'h..p://app.librodequejas.com/1/ws.php?wsdl';
defURL = 'h..p://app.librodequejas.com/1/ws.php';
defSvc = 'LDQ - Application Services';
defPrt = 'LDQ - Application ServicesPort';
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 LDQ___Application_ServicesPortType);
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;


initialization
InvRegistry.RegisterInterface(TypeInfo(LDQ___Application_ServicesPortType), 'h..p://app.librodequejas.com/1/ws.php', 'ISO-8859-1', '', 'LDQ - Application ServicesPortType');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(LDQ___Application_ServicesPortType), 'h..p://app.librodequejas.com/1/ws.php/listComplaints');

end.


Por otra parte me facilitaron como realizarlo mediante php.


# Configuramos parámetros del cliente
$options = array();
$options['authentication'] = SOAP_AUTHENTICATION_BASIC;
$options['login'] = $CFG_username;
$options['password'] = $CFG_password;
$options['trace'] = true;
$options['encoding'] = 'ISO-8859-1';

# Creamos Cliente
$client = new SoapClient( CFG_WSDL, $options );


Espero que puedan ayudarme. Disculpas si abrí un hilo nuevo de algo ya solucionado, estuve buscando y no encontré algo que me pudiera ayudar.