Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/SOAP/Components    [ Add a report in this area ]  
Report #:  14046   Status: Closed
TRIO.DoBeforeExecute  - ignoring changes to var passed to event handler
Project:  Delphi Build #:  2600
Version:    10.0 Submitted By:   daniel sr
Report Type:  Basic functionality failure Date Reported:  6/29/2005 1:45:05 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   226591
Resolution: Fixed (Resolution Comments) Resolved in Build: :
Duplicate of:  None
Voting and Rating
Overall Rating: (2 Total Ratings)
5.00 out of 5
Total Votes: 2
Description
The TRIO.DoBeforeExecute method ignores any changes made in the FOnBeforeExecute event hanlder. If the developer made changes to the ReqW: WideString var passed to the event handler, it just gets ignored.

Here is the method as distributed in BDS2005. (Same bug in Delphi 7)


procedure TRIO.DoBeforeExecute(const MethodName: string; Request: TStream);
var
  StrStrm: TStringStream;
  ReqW: WideString;
begin
  if Assigned(FOnBeforeExecute) then
  begin
    { Ideally we would change the signature of this event to take a Stream.
      The change to stream was necessary for attachment and encoding support.
      And it makes the event consistent.... However, for the sake of
      backward compatibility.... }
    StrStrm := TStringStream.Create('');
    try
      StrStrm.CopyFrom(Request, 0);
      Request.Position := 0;
      ReqW := StrStrm.DataString;
      FOnBeforeExecute(MethodName, ReqW);
    finally
      StrStrm.Free;
    end;
    { NOTE: We ignore the var WideString passed in... ???? }
  end;
end;




Here is the fix that Deepak posted for me in the newsgroups:



In the RIO.Pas, in the TRIO.DoBeforeExecute method, AFTER the following line:

{ NOTE: We ignore the var WideString passed in... ???? }

add:

// DEEPAK
Req := ReqW;

StrStrm := TStringStream.Create(Req);
try
   StrStrm.Position := 0;
   Request.CopyFrom( StrStrm, 0 );
finally
   StrStrm.Free;
end;

{note: Declare Req:string and StrStrm: TStringStream; as local
variables}
Steps to Reproduce:
1) Assign an OnBeforeExecute event handler to a THTTPRio component.

2) Modify the SOAP XML Request using the DOM in the OnBeforeExecute event handler.

3) Verify on the server that your SOAP XML has been unchanged.
Workarounds
In the RIO.Pas, in the TRIO.DoBeforeExecute method, AFTER the following line:

{ NOTE: We ignore the var WideString passed in... ???? }

add:

// DEEPAK
Req := ReqW;

StrStrm := TStringStream.Create(Req);
try
   StrStrm.Position := 0;
   Request.CopyFrom( StrStrm, 0 );
finally
   StrStrm.Free;
end;

{note: Declare Req:string and StrStrm: TStringStream; as local
variables}
Attachment
None
Comments

Registered User at 8/15/2006 10:53:20 AM -
The proposed solution to this problem does not work if the stream comes from a mime attachment (GetMIMEStream). Request.CopyFrom( StrStrm, 0 ) returns the following error: "Method not supported".

From rio.pas:

{$IFDEF ATTACHMENT_SUPPORT}
      if BindingType = btMIME then
        DoBeforeExecute(MethMD.Name, AttachHandler.GetMIMEStream) //Gives the error
      else
{$ENDIF}
        DoBeforeExecute(MethMD.Name, Req); //OK

Server Response from: ETNACODE01