Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

THttprio onBeforeExecute changing the soapRequest

I've imported some wsdl for a project. i want to change the SoapRequest on HttpRio onBeforeExecute event, but as i changed the request, im getting some errors how can i change the request xml file with stringReplace function on this event.

i've tried to change the size of stream, i ve changed the encoding etc. but anyway it didnt work.

example

procedure TForm1.RiomBeforeExecute(const MethodName: string; SOAPRequest: TStream);
var
  sTmp                                  : TStringList;

begin

  sTmp:=TStringList.Create;
  SOAPRequest.Position := 0;
  sTmp.LoadFromStream(SOAPRequest);
  sTmp.Text := StringReplace(sTmp.Text,'blablaa','bla',[RfReplaceAll]);
  sTmp.SaveToStream(SOAPRequest);
  // blaa blaa...
end;
like image 753
Adnan M. TÜRKEN Avatar asked May 11 '10 22:05

Adnan M. TÜRKEN


2 Answers

procedure TForm1.RiomBeforeExecute(const MethodName: string; SOAPRequest: TStream);
var
  sTmp                                  : TStringList;

begin

  sTmp:=TStringList.Create;
  SOAPRequest.Position := 0;
  sTmp.LoadFromStream(SOAPRequest);
  sTmp.Text := StringReplace(sTmp.Text,'blablaa','bla',[RfReplaceAll]);
   **SOAPRequest.Postion:=0**;// i forget this here, as i write the code that worked
  sTmp.SaveToStream(SOAPRequest);
  // blaa blaa...
end;
like image 143
Adnan M. TÜRKEN Avatar answered Sep 28 '22 21:09

Adnan M. TÜRKEN


Possible enhancement... I found, with my situation (and this was in the soap response, btw, in case it matters), that if the resulting request is shorter than the original (and in your case it is), there was crud left over when the new string is written back out to the stream.
ex:

original: <blablaa some stuff>
intended: <bla some stuff>
actual:   <bla some stuff>uff>

Fix:

SOAPRequest.Postion:=0;// i forget this here, as i write the code that worked
SOAPRequest.size := length(sTmp.Text); // Important - set new length before saving.
sTmp.SaveToStream(SOAPRequest);

like image 23
Chris Thornton Avatar answered Sep 28 '22 21:09

Chris Thornton