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