Friday, February 11, 2005

Getting WSDL using basic authentication

Well, this one's tricky. The concept of getting a WSDL that needs authentication to get to - there's one simple way of course, do it yourself, read the WSDL using an Indy component and write it to a local file, and use the local file in Delphi SOAP.

But a far more complicated method is described in my post to the Delphi SOAP newsgroup.

1) Set up an event called OnBeforeGet in THTTPReqResp (the same way
TOnBeforePost is set up)
a) add a private declaration:

// Deepak 11 Feb 2005
FOnBeforeGet: TBeforePostEvent;
// End Deepak 11 Feb 2005

b) in the public part:

// Deepak 11 Feb 2005
{ Events }
property OnBeforeGet: TBeforePostEvent read FOnBeforeGet write FOnBeforeGet;
// End Deepak 11 Feb 2005

2) In the SendGet method of THTTPReqResp, add this line after

Check(not Assigned(Request), False);

Add:

// Deepak 11 Feb 2005
if Assigned(FOnBeforeGet) then
FOnBeforeGet(Self, Request);
// End Deepak 11 Feb 2005

Thats part 1. Now, part 2 is quite complicated, because, as it turns
out, the way the WSDL is fetched is totally inaccessible to us. what
you need to do is:

1) Set up a new event in THTTPRIO - call it TOnGetWSDLItems;

// Deepak 11 Feb 2005
TOnGetWSDLItems = Function( Sender : TObject ) : TWSDLItems of object;
// End Deepak 11 Feb 2005
... (setup an event called OnGetWSDLItems)

2) in the CheckWSDLView procedure, after:

procedure THTTPRIO.CheckWSDLView;
begin
if not Assigned(FWSDLItems) then
begin

add:

If Assigned( FOnGetWSDLItems) then
FWSDLItems := FOnGetWSDLItems( Self );

3) in your main form you'll have to go to HTTPUtil.pas, copy the entire
definition of TStreamLoader over to your main form.

4) Now in the main form, add a funciton like this:

var StreamLoader : TStreamLoader;
begin
StreamLoader := TStreamLoader.Create;
StreamLoader.FUserName := HTTPRIO1.HTTPWebNode.UserName;
StreamLoader.FPassword := HTTPRIO1.HTTPWebNode.Password;
StreamLoader.FHTTPReqResp.GetHTTPReqResp.OnBeforeGet :=
Self.HTTPRIO1HTTPWebNode1BeforePost;
result := TWSDLItems.Create(nil, StreamLoader);
end;

5) Before you do anything, set up your HTTPRIO1 like so:

HTTPRio1.OnGetWSDLItems := OnGetWsdlItems;

Okay, if you're still here, and you've managed to successfully do this,
let me know. I can't post all the code, because it's mostly Borland
code, but it does work. Let me know here if you need it and i'll send
it to you by email.

0 Comments:

Post a Comment

<< Home