我们目前的项目是在 Delphi 6 中。这是我第一次尝试在 Delphi 中使用 Web 服务——我在这个领域的主要经验是使用 C#。无论如何,我需要使用这个项目的 Web 服务。我遇到了一些问题,导入 wsdl ( http://txportwst.txhubpr.com/txserver/1?wsdl ) 会生成两个单元。单元的类型引用和依赖项存在一些问题,使其无法立即构建,但我能够纠正这些问题。
从测试表单中,我添加了使用服务的代码,但我收到了一个没有意义的错误。该方法期望发送类型为 (requestIVULoto) 的 var,但错误将指示其他情况。我将事情从 xmethods.net 切换到随机服务,并且能够获得一个非常简单的服务(reto.checkit.ch/Scripts/Lotto.dll/wsdl/IgetNumbers),它告诉我我在正确的路径,但是另一个稍微复杂一点的(www.xmlme.com/WSDailyNet.asmx?WSDL)并没有产生与我从需要使用的服务接收到的相同错误。
我能够通过服务引用和 10 行代码获得在 C# 中运行所需的服务,这很容易,但让 Delphi 更加令人沮丧。如果这不起作用,我正在考虑向 com 公开一个 .net 类库。我宁愿在 Delphi 中本地执行此操作,但我担心 Delphi 6 太旧了。
有任何想法吗?
作为旁注,在 C#..
IvuLoto.IvuSvc.ivuLotoData ild = new IvuLoto.IvuSvc.ivuLotoData();
ild = client.requestIVULoto(txn); // returns type ivuLotoData.
错误
---------------------------
Debugger Exception Notification
---------------------------
Project TEST.exe raised exception class Exception with message 'The parameter is incorrect.'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
测试表格
...
implementation
uses
IVU, IVUSvc;
...
procedure TFormTest.Button1Click(Sender: TObject);
var
ivu: requestIVULoto;
txn: transaction;
rio: THTTPRIO;
begin
rio := THTTPRIO.Create(nil);
rio.wsdlLocation := 'http://txportwst.txhubpr.com/txserver/1?wsdl';
rio.Service := 'txServerService';
rio.Port := 'txServerPort';
txn := transaction.Create();
txn.txDate := '08/14/2014 00:00:00';
txn.merchantId := 'REMOVED';
txn.terminalId := IntToStr(Workstation.WorkstationId);
txn.terminalPassword := 'REMOVED';
txn.txType := SALE; //IVU.txType
txn.tenderType := CASH; //IVU.tenderType
txn.subTotal := '100.00';
txn.municipalTax := '1.00';
txn.stateTax := '6.00';
txn.total := '107.00';
ivu := requestIVULoto.Create();
ivu.transaction := txn;
(rio as txServer).requestIVULoto(ivu);
rio.Free;
ivu.Free;
txn.Free;
end;
wsdl 导入生成的单位
Unit IVUSvc;
interface
uses Types, XSBuiltIns, IVU;
type
TxServer = interface(IInvokable)
['{07415916-265C-448F-B69F-0AAF9CBDDC1C}']
procedure requestIVULoto(var parameters: requestIVULoto); stdcall;
procedure requestTxInfo(var parameters: requestTxInfo); stdcall;
end;
implementation
uses InvokeRegistry;
initialization
InvRegistry.RegisterInterface(TypeInfo(TxServer), '', 'UTF-8');
end.
和
Unit IVU;
interface
uses InvokeRegistry, Types, XSBuiltIns, XMLDoc;
type
requestIVULoto = class;
transaction = class;
requestIVULotoResponse = class;
ivuLotoData = class;
requestTxInfo = class;
txInfoRequest = class;
requestTxInfoResponse = class;
txInfoResponse = class;
txInfo = class;
{ tenderType }
tenderType = (CASH, CREDIT, DEBIT, EBT, ATH, UNSPECIFIED_CARD, UNKNOWN);
{ txType }
txType = (SALE, REFUND);
{ txPosResponseStatus }
txPosResponseStatus = (SUCCESS, AUTHENTICATION_FAILED, MISSING_PARAMETERS, INVALID_PARAMETERS, SERVER_ERROR);
{ txInfoResponseStatus }
txInfoResponseStatus = txPosResponseStatus;//(SUCCESS, AUTHENTICATION_FAILED, MISSING_PARAMETERS, INVALID_PARAMETERS, SERVER_ERROR);
{ requestIVULoto }
requestIVULoto = class(TRemotable)
private
Ftransaction: transaction;
published
property transaction: transaction read Ftransaction write Ftransaction;
end;
{ transaction }
transaction = class(TRemotable)
private
FmerchantId: WideString;
FmunicipalTax: WideString;
FstateTax: WideString;
FsubTotal: WideString;
FtenderType: tenderType;
FterminalId: WideString;
FterminalPassword: WideString;
Ftotal: WideString;
FtxDate: WideString;
FtxType: txType;
published
property merchantId: WideString read FmerchantId write FmerchantId;
property municipalTax: WideString read FmunicipalTax write FmunicipalTax;
property stateTax: WideString read FstateTax write FstateTax;
property subTotal: WideString read FsubTotal write FsubTotal;
property tenderType: tenderType read FtenderType write FtenderType;
property terminalId: WideString read FterminalId write FterminalId;
property terminalPassword: WideString read FterminalPassword write FterminalPassword;
property total: WideString read Ftotal write Ftotal;
property txDate: WideString read FtxDate write FtxDate;
property txType: txType read FtxType write FtxType;
end;
{ requestIVULotoResponse }
requestIVULotoResponse = class(TRemotable)
private
FIVULoto: ivuLotoData;
published
property IVULoto: ivuLotoData read FIVULoto write FIVULoto;
end;
{ ivuLotoData }
ivuLotoData = class(TRemotable)
private
FivuLoto: WideString;
FcontrolNumber: WideString;
FdrawNumber: WideString;
FdrawDate: WideString;
Fstatus: txPosResponseStatus;
FerrorDetail: WideString;
published
property ivuLoto: WideString read FivuLoto write FivuLoto;
property controlNumber: WideString read FcontrolNumber write FcontrolNumber;
property drawNumber: WideString read FdrawNumber write FdrawNumber;
property drawDate: WideString read FdrawDate write FdrawDate;
property status: txPosResponseStatus read Fstatus write Fstatus;
property errorDetail: WideString read FerrorDetail write FerrorDetail;
end;
{ requestTxInfo }
requestTxInfo = class(TRemotable)
private
Farg0: txInfoRequest;
published
property arg0: txInfoRequest read Farg0 write Farg0;
end;
{ txInfoRequest }
txInfoRequest = class(TRemotable)
private
FendDate: WideString;
FmerchantId: WideString;
FstartDate: WideString;
FterminalId: WideString;
FterminalPassword: WideString;
published
property endDate: WideString read FendDate write FendDate;
property merchantId: WideString read FmerchantId write FmerchantId;
property startDate: WideString read FstartDate write FstartDate;
property terminalId: WideString read FterminalId write FterminalId;
property terminalPassword: WideString read FterminalPassword write FterminalPassword;
end;
{ requestTxInfoResponse }
requestTxInfoResponse = class(TRemotable)
private
Freturn: txInfoResponse;
published
property return: txInfoResponse read Freturn write Freturn;
end;
{ txInfo }
txInfo = class(TRemotable)
private
FcontrolNumber: WideString;
FdrawDate: WideString;
FdrawNumber: WideString;
FivuLottoNumber: WideString;
FmunicipalTax: WideString;
FstateTax: WideString;
FsubTotal: WideString;
FtenderType: tenderType;
Ftotal: WideString;
FtransactionDate: WideString;
FtransactionType: txType;
published
property controlNumber: WideString read FcontrolNumber write FcontrolNumber;
property drawDate: WideString read FdrawDate write FdrawDate;
property drawNumber: WideString read FdrawNumber write FdrawNumber;
property ivuLottoNumber: WideString read FivuLottoNumber write FivuLottoNumber;
property municipalTax: WideString read FmunicipalTax write FmunicipalTax;
property stateTax: WideString read FstateTax write FstateTax;
property subTotal: WideString read FsubTotal write FsubTotal;
property tenderType: tenderType read FtenderType write FtenderType;
property total: WideString read Ftotal write Ftotal;
property transactionDate: WideString read FtransactionDate write FtransactionDate;
property transactionType: txType read FtransactionType write FtransactionType;
end;
{ txInfoList }
txInfoList = class(TXMLNodeCollection)
end;
{ txInfoResponse }
txInfoResponse = class(TRemotable)
private
FerrorDetail: WideString;
FtxCount: Integer;
Ftransactions: txInfoList;
Fstatus: txInfoResponseStatus;
published
property errorDetail: WideString read FerrorDetail write FerrorDetail;
property txCount: Integer read FtxCount write FtxCount;
property transactions: txInfoList read Ftransactions write Ftransactions;
property status: txInfoResponseStatus read Fstatus write Fstatus;
end;
implementation
initialization
RemClassRegistry.RegisterXSInfo(TypeInfo(tenderType),'http://txserver.sut.softekpr.com/1','tenderType','');
RemClassRegistry.RegisterXSInfo(TypeInfo(txType),'http://txserver.sut.softekpr.com/1','txType','');
RemClassRegistry.RegisterXSInfo(TypeInfo(txPosResponseStatus),'http://txserver.sut.softekpr.com/1','txPosResponseStatus','');
RemClassRegistry.RegisterXSInfo(TypeInfo(txInfoResponseStatus),'http://txserver.sut.softekpr.com/1','txInfoResponseStatus','');
RemClassRegistry.RegisterXSInfo(TypeInfo(requestIVULoto),'http://txserver.sut.softekpr.com/1','requestIVULoto','');
RemClassRegistry.RegisterXSInfo(TypeInfo(requestIVULotoResponse),'http://txserver.sut.softekpr.com/1','requestIVULotoResponse','');
RemClassRegistry.RegisterXSInfo(TypeInfo(requestTxInfo),'http://txserver.sut.softekpr.com/1','requestTxInfo','');
RemClassRegistry.RegisterXSInfo(TypeInfo(requestTxInfoResponse),'http://txserver.sut.softekpr.com/1','requestTxInfoResponse','');
RemClassRegistry.RegisterXSClass(requestIVULoto,'http://txserver.sut.softekpr.com/1','requestIVULoto','');
RemClassRegistry.RegisterXSClass(transaction,'http://txserver.sut.softekpr.com/1','transaction','');
RemClassRegistry.RegisterXSClass(requestIVULotoResponse,'http://txserver.sut.softekpr.com/1','requestIVULotoResponse','');
RemClassRegistry.RegisterXSClass(ivuLotoData,'http://txserver.sut.softekpr.com/1','ivuLotoData','');
RemClassRegistry.RegisterXSClass(requestTxInfo,'http://txserver.sut.softekpr.com/1','requestTxInfo','');
RemClassRegistry.RegisterXSClass(txInfoRequest,'http://txserver.sut.softekpr.com/1','txInfoRequest','');
RemClassRegistry.RegisterXSClass(requestTxInfoResponse,'http://txserver.sut.softekpr.com/1','requestTxInfoResponse','');
RemClassRegistry.RegisterXSClass(txInfoResponse,'http://txserver.sut.softekpr.com/1','txInfoResponse','');
RemClassRegistry.RegisterXSClass(txInfo,'http://txserver.sut.softekpr.com/1','txInfo','');
end.