1

I have a web service client created with DELPHI XE 5, i used THTTPRIO, imported wsdl and created the ".pas" files. The server of web service request a preemptive basic authentication (that work fine with SoapUI); I know how to make authentication with user and password of THTTPReqResp.

rio := THTTPRIO.Create(nil);
HTTPReqResp1 := THTTPReqResp.Create(rio);
HTTPReqResp1.UserName := sUserName;
HTTPReqResp1.Password := sPasswordEncrypted;

But I don't connect to the web service because I don't know ho to make preemptive and if it's possible in Delphi.

Can anyone help me ? :)

  • 1
    If you want to look up connection information dynamically at runtime from a WSDL document, you can set the WSDLLocation property. After setting WSDLLocation, select values for the Service and Port properties from drop-down lists in the object inspector to fully specify the binding you want to use. – fpiette Feb 26 '20 at 14:58
  • Hi fpiette, Thank you for your answer. In my cas i'm using the "RIO.URL := Addr;" not the part " RIO.WSDLLocation := Addr; RIO.Service := defSvc; RIO.Port := defPrt; " When I'm trying to launch an request I receive the error 401 (Unauthorized). But I receive that message only in delphi, when I'm in "preemptive connection" into SUOP UI it's find. It's why I'm trying to do the same with Delphi. – Christopher Zaza Feb 27 '20 at 09:48
  • Why do you create instance of `THTTPReqResp` in run-time? `THTTPRIO` will ignore it unless you link the instances in run-time: `rio.HTTPWebNode := HTTPReqResp1`. `THTTPRIO` internally creates its own instance. You can perfectly configure its properties (incl. `UserName` and `Password`) in design-time via object inspector. To do that in run-time use `rio.HTTPWebNode.UserName` and `rio.HTTPWebNode.Password`. – Peter Wolf Feb 27 '20 at 14:40

1 Answers1

0

I just found how It's possible to use "preemprive" connexion in DELPHI. You have to modify the OnBeforePost of your "rio.HTTPWebNode" like this :

var
rio  : THTTPRIO;
HTTPReqResp1: THTTPReqResp;
uselessObject: TUselessClass;
try
    rio := THTTPRIO.Create(nil);
    uselessObject := TUselessClass.Create();
    rio.HTTPWebNode.GetHTTPReqResp.OnBeforePost := 
    uselessObject.HTTPRIOHTTPWebNode1BeforePost;

With this procedure :

procedure TUselessClass.HTTPRIOHTTPWebNode1BeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);
var
    auth,toEncode: string;
begin
    toEncode := Format('%s:%s',[sUserName,sPasswordEncrypted]);
    auth := 'Authorization: Basic ' + TIdEncoderMIME.EncodeString(toEncode);
    HttpAddRequestHeaders(Data, PChar(auth), Length(auth), HTTP_ADDREQ_FLAG_ADD);
end;