carmeloconny
carmeloconny

Reputation: 65

Query WSDL-SOAP with Delphi app client, autentication Base

Through delphi I am making a client to communicate with a ws.

WSDL:

  visualizzaErogatoPT = interface(IInvokable)
  ['{AD9DB9DE-E3E4-1FD0-171D-FD78913E0E54}']
    function  visualizzaErogato(const VisualizzaErogatoRichiesta: VisualizzaErogatoRichiesta): VisualizzaErogatoRicevuta; stdcall;
  end;

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

  VisualizzaErogatoRichiesta = class(TRemotable)
  private
    FpinCode: stringType;
    FcodiceRegioneErogatore: stringType;
    FcodiceAslErogatore: stringType;
    FcodiceSsaErogatore: stringType;
    Fpwd: pwdType;
    Fnre: nreType;
    FcfAssistito: stringType;
    FcfAssistito_Specified: boolean;
    FtipoOperazione: tipoOperazioneType;
    procedure SetcfAssistito(Index: Integer; const AstringType: stringType);
    function  cfAssistito_Specified(Index: Integer): boolean;
  public
    constructor Create; override;
  published
    property pinCode:                stringType          read FpinCode write FpinCode;
    property codiceRegioneErogatore: stringType          read FcodiceRegioneErogatore write FcodiceRegioneErogatore;
    property codiceAslErogatore:     stringType          read FcodiceAslErogatore write FcodiceAslErogatore;
    property codiceSsaErogatore:     stringType          read FcodiceSsaErogatore write FcodiceSsaErogatore;
    property pwd:                    pwdType             read Fpwd write Fpwd;
    property nre:                    nreType             read Fnre write Fnre;
    property cfAssistito:            stringType          Index (IS_OPTN) read FcfAssistito write SetcfAssistito stored cfAssistito_Specified;
    property tipoOperazione:         tipoOperazioneType  read FtipoOperazione write FtipoOperazione;
  end;

procedure TMainF.Button2Click(Sender: TObject);
var
  richiesta: VisualizzaErogatoRichiesta;
  ricevuta: VisualizzaErogatoRicevuta;
begin
  richiesta.codiceRegioneErogatore := '190';
  richiesta.codiceAslErogatore := '201';
  richiesta.codiceSsaErogatore := '888888';
  richiesta.pwd := '';
  richiesta.nre := '1900A4005026299';
  richiesta.tipoOperazione := '1';
  try
    ricevuta :=  (HTTPRIO1 as visualizzaErogatoPT).visualizzaErogato(richiesta); 
    label1.Caption := ricevuta.nre;
  except
    on E: Exception do
      showmessage(E.Message);
  end;
end;

I get an error.(EsoapDomConvertError .... Soap classes must device from Tremotable)


For the authentication I used component: HTTPRIO and HTTPReqResp

procedure TMainF.HTTPReqResp1BeforePost(const HTTPReqResp: THTTPReqResp;
  Data: Pointer);
var
  auth: String;
  FUserName, FPassword : string;
begin
  FUserName:='XXXXXXXX';
  FPassword:='XXXXXXXX';
  auth := 'Authorization: Basic ' + TNetEncoding.Base64.Encode(FUserName + ':' + FPassword);
  HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
end;

I do not know how to make these components work.

I have tried various ways without result. Do I have to use "basic" authentication components(HTTPRIO and HTTPReqResp) required by the WS? I'm looking for a guide to build this.

Upvotes: 1

Views: 277

Answers (1)

mjn42
mjn42

Reputation: 840

For HTTP Basic Authentication, this code (placed before calling the SOAP service) should work:

HTTPRio1.HTTPWebNode.UserName := 'XXXXXXXX';
HTTPRio1.HTTPWebNode.Password := 'XXXXXXXX';

instead of the event handler TMainF.HTTPReqResp1BeforePost

Upvotes: 1

Related Questions