簡體   English   中英

DELPHI:RIO OnBeforeExecute

[英]DELPHI: RIO OnBeforeExecute

我有一個從外部來源生成的SOAP服務,該服務給了我一些錯誤。 我想捕獲實際發送給SOAP服務的XML,然后發現有人提到在RIO上執行OnBeforeExecute,但不確定如何實現。 我通常不使用Delphi,而只是維護此遺留程序,所以越詳細越好!

這是生成的API / SOAP代碼(RIO_OnBeforeExecute是我嘗試放入的內容,但它抱怨類型不兼容:方法指針和常規過程):

  ExpressSoap = interface(IInvokable)
  ['{83D77575-DBDE-3A05-D048-60B2F6BCDFE6}']
    function  HealthCheck(const credentials: Credentials; const application: Application): Response; stdcall;
  end;

function GetExpressSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ExpressSoap;
procedure RIO_BeforeExecute(const MethodName: string; var SOAPRequest: WideString);

implementation

function GetExpressSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ExpressSoap;
const
  defWSDL = 'https://certtransaction.elementexpress.com/express.asmx?wsdl';
  defURL  = 'https://certtransaction.elementexpress.com/express.asmx';
  defSvc  = 'Express';
  defPrt  = 'ExpressSoap';
var
  RIO: THTTPRIO;
begin

  RIO.OnBeforeExecute := RIO_BeforeExecute;

  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as ExpressSoap);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;

procedure RIO_BeforeExecute(const MethodName: string; var SOAPRequest: WideString);
begin
  MessageDlg('Hello', mtConfirmation, [mbOK] ,0);
end;

這是調用HealthCheck方法的代碼(cEPS_ *項目是代碼前面定義的常量):

procedure TForm1.Button1Click(Sender: TObject);
var
  Headers : ISOAPHeaders;
  aResult: c_ExpressPSAPI.Response;
begin
  try
    FEPS_SoapService := c_ExpressPSAPI.GetExpressSoap();
    FEPS_Headers := (FEPS_SoapService as ISOAPHeaders);

    FEPS_Application := c_ExpressPSAPI.Application.Create();
    FEPS_Application.ApplicationID := cEPS_ApplicationID;
    FEPS_Application.ApplicationName := cEPS_ApplicationName;
    FEPS_Credentials := c_ExpressPSAPI.Credentials.Create();
    FEPS_Credentials.AccountID := cEPS_AccountID;
    FEPS_Credentials.AccountToken := cEPS_AccountToken;
    FEPS_Credentials.AcceptorID := cEPS_AcceptorID;
    FEPS_Credentials.NewAccountToken := '';


    aResult := c_ExpressPSAPI.Response.Create;
    aResult := FEPS_SoapService.HealthCheck(FEPS_Credentials, FEPS_Application);

  except
    on E : ERemotableException do
      ShowMessage(E.ClassName + ' error raised, with message : ' + E.FaultDetail + ' :: '
                    + E.Message);

  end;

end;

我能夠解決這個問題,並發布答案,以防其他人發現此問題。

首先,我必須在表單中添加一個THTTPRIO(名為HTTPRIO1)組件,然后在該組件(名為HTTPRIO1BeforeExecute)上設置OnBeforeExecute事件。 完成后,我將HTTPRIO1對象傳遞給與OnBeforeExecute方法綁定的GetExpressSOAP方法:

  FEPS_SoapService := c_ExpressPSAPI.GetExpressSoap(System.False, '', HTTPRIO1);

然后,我可以像這樣使用OnBeforeExecute:

procedure TForm1.HTTPRIO1BeforeExecute(const MethodName: string;
  var SOAPRequest: WideString);
var
  tmpString: TStringList;
begin
  try
    Memo1.Lines.Append(SOAPRequest);
  except
    on ER : ERemotableException do
      ShowMessage(ER.ClassName + ' error raised, with message : ' + ER.FaultDetail);

    on E : Exception do
      ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message);
  end;
end;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM