Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Incluir header en webservice (https://www.clubdelphi.com/foros/showthread.php?t=94982)

Quim Herrera 11-12-2020 12:01:54

Incluir header en webservice
 
Hola,

Tengo un problema al consumir un webservice de una empresa de transportes. Hay que llamar a un primer webservice para identificarte y te devuelve un id que debes mandar al segundo webservice dentro del <header> junto con los datos para dar de alta el envio.
He importado los wsdl con delphi tokyo y la cabecera está allí:
Código Delphi [-]
  ROClientIDHeader     = class;  
  .....
  
   // ************************************************************************ //
  // XML       : ROClientIDHeader, global, 
  // Namespace : http://tempuri.org/
  // Info      : Header
  // ************************************************************************ //
  ROClientIDHeader = class(TSOAPHeader)
  private
    FID: string;
    FID_Specified: boolean;
    procedure SetID(Index: Integer; const Astring: string);
    function  ID_Specified(Index: Integer): boolean;
  published
    property ID: string  Index (IS_OPTN) read FID write SetID stored ID_Specified;
  end;
  .....
  
  
procedure ROClientIDHeader.SetID(Index: Integer; const Astring: string);
begin
  FID := Astring;
  FID_Specified := True;
end;

function ROClientIDHeader.ID_Specified(Index: Integer): boolean;
begin
  Result := FID_Specified;
end;

...
  InvRegistry.RegisterHeaderClass(TypeInfo(WebServService), ROClientIDHeader, 'ROClientID', 'http://tempuri.org/');

Pero no sé como incluirla en el xml al hacer el envio.
Se está enviando:

Código:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <SOAP-ENV:Body>
                <WebServService___GrabaEnvio19 xmlns="http://tempuri.org/">
                        <strCodAgeCargo>099999</strCodAgeCargo>
                        <strCodAgeOri>099999</strCodAgeOri>
        ...
                        <strCodPuntoConveniencia/>
                </WebServService___GrabaEnvio19>
        </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

y deberia enviarlo con la cabecera:

Código:

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soap:Header>
                <ROClientIDHeader xmlns="http://tempuri.org/">
                        <ID>{xxxx-xxxxx-xxxxx-xxxx}</ID>
                </ROClientIDHeader>
        </soap:Header>
        <SOAP-ENV:Body>
                <WebServService___GrabaEnvio19 xmlns="http://tempuri.org/">
                        <strCodAgeCargo>099999</strCodAgeCargo>
                        <strCodAgeOri>099999</strCodAgeOri>
        ...
                        <strCodPuntoConveniencia/>
                </WebServService___GrabaEnvio19>
        </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

¿ Alguien podria ayudarme a incluir la cabecera en el XML ?



Muchas gracias

Neftali [Germán.Estévez] 14-12-2020 09:25:10

No comentas qué componentes estás utilizando.

En el caso de TRESTclient, puedes añadir los HAEDERS como parámetros de la cabecera.
Algo simila a esto:

Código Delphi [-]
FRestClient.AddParameter('ID', 'XXX-XXXX-XXXX-XXXX', TRESTRequestParameterKind.pkHTTPHEADER);

egostar 14-12-2020 19:47:01

Hola

Los Header se envían antes de llamar el método que vas a consumir. En tu caso yo haría algo así, lo hago al aire, ajusta lo que se necesite:

Código Delphi [-]

var
  wsID: ID; 

begin
  //Crear servicio

  //****************
  wsID := ID.Create;
  wsID.Value := 'valor';
  (servicio as ISOAPHeader).Send(wsID);
  //****************

  //Llamar al método
end;

Saludos

Quim Herrera 15-12-2020 12:25:57

Cita:

Empezado por egostar (Mensaje 539438)
Hola

Los Header se envían antes de llamar el método que vas a consumir. En tu caso yo haría algo así, lo hago al aire, ajusta lo que se necesite:

Código Delphi [-]

var
  wsID: ID; 

begin
  //Crear servicio

  //****************
  wsID := ID.Create;
  wsID.Value := 'valor';
  (servicio as ISOAPHeader).Send(wsID);
  //****************

  //Llamar al método
end;

Saludos

Hola,

La solución de egostar funciona perfectamente (añadiendo una 's' ;) ) :

Código Delphi [-]
 ( servicio as ISOAPHeaders ).Send(wsID);

Muchísimas gracias a todos.
Saludos,


La franja horaria es GMT +2. Ahora son las 10:58:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi