0

我有一个从外部源生成的 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;
4

1 回答 1

3

我能够得到这个工作并发布答案以防其他人发现这个问题。

首先,我必须在表单中添加一个 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;
于 2013-04-16T17:58:22.993 回答