THttprio onBeforeExecute 更改soapRequest
我已经为一个项目导入了一些 wsdl 。 我想更改 HttpRio onBeforeExecute 事件上的 SoapRequest,但是 当我更改请求时,我收到一些错误,如何更改请求 xml 文件 在此事件上使用 stringReplace 函数。
我尝试过更改流的大小,更改了编码等,但无论如何它都不起作用。
例子
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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能的增强...我发现,根据我的情况(这是在肥皂响应中,顺便说一句,以防万一),如果生成的请求比原始请求短(在您的情况下是这样),则存在 CRUD当新字符串写回到流中时留下的内容。
ex:
Fix:
SOAPRequest.Postion:=0;// 我在这里忘记了这一点,因为我编写了有效的代码
SOAPRequest.size := length(sTmp.Text); // 重要 - 在保存之前设置新长度。
sTmp.SaveToStream(SOAPRequest);
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:
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);