【问题标题】:Delphi 2010 or c# - webserviceDelphi 2010 或 c# - 网络服务
【发布时间】:2011-01-17 16:56:16
【问题描述】:

我正在尝试将 webserivce 与 Delphi 2010 一起使用,但我无法让 gettransaction 正常工作。我如何使用 delphi 从这个函数中获取响应?我可以插入参数来调用它,但没有得到响应。

如何使用 Delphi 或 c# 读取响应?

这是 XML:

<?xml version="1.0" encoding="UTF-8"?>

      <xsd:complexType name="getTransactions">
        <xsd:sequence>
          <xsd:element name="date_from" nillable="true" type="xsd:string"/>
          <xsd:element name="date_to" nillable="true" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="getTransactionsResponse">
        <xsd:sequence>
          <xsd:element name="voucherTransactions" nillable="true" type="tns:ArrayOfVoucherTransaction"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="VoucherTransaction">
        <xsd:sequence>
          <xsd:element name="GLOBAL_SERIAL_NUMBER" nillable="true" type="xsd:string"/>
          <xsd:element name="DATE_CREATED" nillable="true" type="xsd:string"/>
          <xsd:element name="AMOUNT" nillable="true" type="xsd:string"/>
          <xsd:element name="STATUS" nillable="true" type="xsd:string"/>
          <xsd:element name="PIN_CODE" nillable="true" type="xsd:string"/>
          <xsd:element name="EXT_REF" nillable="true" type="xsd:string"/>
          <xsd:element name="STORE_ID" nillable="true" type="xsd:string"/>
          <xsd:element name="TERMINAL_ID" nillable="true" type="xsd:string"/>
          <xsd:element name="EMP_ID" nillable="true" type="xsd:string"/>
          <xsd:element name="DATE_INVALIDATED" nillable="true" type="xsd:string"/>
          <xsd:element name="EXPIRY_DATE" nillable="true" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="ArrayOfVoucherTransaction"><xsd:sequence>

      </xsd:complexType>
             <xsd:element name="getTransactions" type="tns:getTransactions"/>

我使用参数 From 01.01.2011 和 To 17.01.2011 使用 gettransaction 调用网络服务器

这是delphi 2010中的功能

procedure TForm2.Button2Click(Sender: TObject);
var
  rr     : voucher17.getTransactions2; 
  getrr    : voucher17.getTransactionsResponse2;
  aa2    : voucher17.ArrayOfVoucherTransaction;
  iinn   : integer; 
  test3  : voucher17.VoucherTransaction; 
  test4  : voucher17.ArrayOfVoucherTransaction;
begin


rr := getTransactions2.Create;
rr.date_from := '09.01.2011';
rr.date_to   := '10.01.2011';

getrr := GetVoucher_PortType.getTransactions(rr);

// here is the problem but i dont know how to read from the array
 i have try to assign getrr to test3, test4, aa2 but still cant figure out what to do to get the data.

end;

这是从soapui返回的,所以这是可行的,但是如何使用delphi来读取呢?

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <SOAP-ENV:Header xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"/>

   <SOAP-ENV:Body>

      <ser-root:getTransactionsResponse xmlns:ser-root="https://webmethods.someurl.com/TopUpServices/webServices/Voucher">

         <voucherTransactions>

            <ArrayOfVoucherTransactionItem>

               <GLOBAL_SERIAL_NUMBER>3132765</GLOBAL_SERIAL_NUMBER>

               <DATE_CREATED>2011-01-17 20:34:49.0</DATE_CREATED>

               <AMOUNT>500</AMOUNT>

               <STATUS>1</STATUS>

               <PIN_CODE>123</PIN_CODE>

               <EXT_REF>772</EXT_REF>

               <STORE_ID>772</STORE_ID>

               <TERMINAL_ID>772</TERMINAL_ID>

               <EMP_ID>772</EMP_ID>

               <DATE_INVALIDATED>2011-01-17 20:34:49.0</DATE_INVALIDATED>

               <EXPIRY_DATE>2011-01-17 20:34:49.0</EXPIRY_DATE>

            </ArrayOfVoucherTransactionItem>

            <ArrayOfVoucherTransactionItem>

               <GLOBAL_SERIAL_NUMBER>3133023</GLOBAL_SERIAL_NUMBER>

               <DATE_CREATED>2011-01-17 20:34:49.0</DATE_CREATED>

               <AMOUNT>500</AMOUNT>

               <STATUS>1</STATUS>

               <PIN_CODE>123</PIN_CODE>

               <EXT_REF>772</EXT_REF>

               <STORE_ID>772</STORE_ID>

               <TERMINAL_ID>772</TERMINAL_ID>

               <EMP_ID>772</EMP_ID>

               <DATE_INVALIDATED>2011-01-17 20:34:49.0</DATE_INVALIDATED>

               <EXPIRY_DATE>2011-01-17 20:34:49.0</EXPIRY_DATE>

            </ArrayOfVoucherTransactionItem>

         </voucherTransactions>

      </ser-root:getTransactionsResponse>

   </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

这是代理

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described beloow:
// WSDL     : https://webmethods.someurl.com/ws/TopUpServices.webServices:Voucher?WSDL
//  >Import : https://webmethods.someurl.com/ws/TopUpServices.webServices:Voucher?WSDL>0
// Encoding : UTF-8
// Codegen  : [wfAutoDestroyMembers-, wfMapArraysToClasses+, wfProcessHeaders-, wfUseSettersAndGetters+, wfForceSOAP11+, wfForceSOAP12+]
// Version  : 1.0
// (10.1.2011 15:31:05 - - $Rev: 25127 $)
// ************************************************************************ //

unit Voucher17;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns, Dialogs;

const
  IS_OPTN = $0001;
  IS_UNBD = $0002;
  IS_NLBL = $0004;
  IS_UNQL = $0008;


type

  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Embarcadero types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:string          - "http://www.w3.org/2001/XMLSchema"[Gbl]

  getTransactions      = class;                 { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[Lit][GblCplx] }
  getTransactionsResponse = class;              { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[Lit][GblCplx] }
  VoucherTransaction   = class;                 { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[GblCplx] }
  getTransactions2     = class;                 { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[Lit][GblElm] }
  getTransactionsResponse2 = class;             { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[Lit][GblElm] }
  ArrayOfVoucherTransaction = class;            { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[GblCplx] }


  // ************************************************************************ //
  // XML       : getTransactions, global, <complexType>
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // Serializtn: [xoLiteralParam]
  // Info      : Wrapper
  // ************************************************************************ //
  getTransactions = class(TRemotable)
  private
    Fdate_from: string;
    Fdate_to: string;
    function  Getdate_from(Index: Integer): string;
    procedure Setdate_from(Index: Integer; const Astring: string);
    function  Getdate_to(Index: Integer): string;
    procedure Setdate_to(Index: Integer; const Astring: string);
  public
    constructor Create; override;
  published
    property date_from: string  Index (IS_NLBL or IS_UNQL) read Getdate_from write Setdate_from;
    property date_to:   string  Index (IS_NLBL or IS_UNQL) read Getdate_to write Setdate_to;
  end;



  // ************************************************************************ //
  // XML       : getTransactionsResponse, global, <complexType>
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // Serializtn: [xoLiteralParam]
  // Info      : Wrapper
  // ************************************************************************ //
  getTransactionsResponse = class(TRemotable)
  private
    FvoucherTransactions: ArrayOfVoucherTransaction;
    function  GetvoucherTransactions(Index: Integer): ArrayOfVoucherTransaction;
    procedure SetvoucherTransactions(Index: Integer; const AArrayOfVoucherTransaction: ArrayOfVoucherTransaction);
  public
    constructor Create; override;
  published
    property voucherTransactions: ArrayOfVoucherTransaction  Index (IS_NLBL or IS_UNQL) read GetvoucherTransactions write SetvoucherTransactions;
  end;



  // ************************************************************************ //
  // XML       : VoucherTransaction, global, <complexType>
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // ************************************************************************ //
  VoucherTransaction = class(TRemotable)
  private
    FGLOBAL_SERIAL_NUMBER: string;
    FDATE_CREATED: string;
    FAMOUNT: string;
    FSTATUS: string;
    FPIN_CODE: string;
    FEXT_REF: string;
    FSTORE_ID: string;
    FTERMINAL_ID: string;
    FEMP_ID: string;
    FDATE_INVALIDATED: string;
    FEXPIRY_DATE: string;
    function  GetGLOBAL_SERIAL_NUMBER(Index: Integer): string;
    procedure SetGLOBAL_SERIAL_NUMBER(Index: Integer; const Astring: string);
    function  GetDATE_CREATED(Index: Integer): string;
    procedure SetDATE_CREATED(Index: Integer; const Astring: string);
    function  GetAMOUNT(Index: Integer): string;
    procedure SetAMOUNT(Index: Integer; const Astring: string);
    function  GetSTATUS(Index: Integer): string;
    procedure SetSTATUS(Index: Integer; const Astring: string);
    function  GetPIN_CODE(Index: Integer): string;
    procedure SetPIN_CODE(Index: Integer; const Astring: string);
    function  GetEXT_REF(Index: Integer): string;
    procedure SetEXT_REF(Index: Integer; const Astring: string);
    function  GetSTORE_ID(Index: Integer): string;
    procedure SetSTORE_ID(Index: Integer; const Astring: string);
    function  GetTERMINAL_ID(Index: Integer): string;
    procedure SetTERMINAL_ID(Index: Integer; const Astring: string);
    function  GetEMP_ID(Index: Integer): string;
    procedure SetEMP_ID(Index: Integer; const Astring: string);
    function  GetDATE_INVALIDATED(Index: Integer): string;
    procedure SetDATE_INVALIDATED(Index: Integer; const Astring: string);
    function  GetEXPIRY_DATE(Index: Integer): string;
    procedure SetEXPIRY_DATE(Index: Integer; const Astring: string);
  published
    property GLOBAL_SERIAL_NUMBER: string  Index (IS_NLBL or IS_UNQL) read GetGLOBAL_SERIAL_NUMBER write SetGLOBAL_SERIAL_NUMBER;
    property DATE_CREATED:         string  Index (IS_NLBL or IS_UNQL) read GetDATE_CREATED write SetDATE_CREATED;
    property AMOUNT:               string  Index (IS_NLBL or IS_UNQL) read GetAMOUNT write SetAMOUNT;
    property STATUS:               string  Index (IS_NLBL or IS_UNQL) read GetSTATUS write SetSTATUS;
    property PIN_CODE:             string  Index (IS_NLBL or IS_UNQL) read GetPIN_CODE write SetPIN_CODE;
    property EXT_REF:              string  Index (IS_NLBL or IS_UNQL) read GetEXT_REF write SetEXT_REF;
    property STORE_ID:             string  Index (IS_NLBL or IS_UNQL) read GetSTORE_ID write SetSTORE_ID;
    property TERMINAL_ID:          string  Index (IS_NLBL or IS_UNQL) read GetTERMINAL_ID write SetTERMINAL_ID;
    property EMP_ID:               string  Index (IS_NLBL or IS_UNQL) read GetEMP_ID write SetEMP_ID;
    property DATE_INVALIDATED:     string  Index (IS_NLBL or IS_UNQL) read GetDATE_INVALIDATED write SetDATE_INVALIDATED;
    property EXPIRY_DATE:          string  Index (IS_NLBL or IS_UNQL) read GetEXPIRY_DATE write SetEXPIRY_DATE;
  end;



  // ************************************************************************ //
  // XML       : getTransactions, global, <element>
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // Info      : Wrapper
  // ************************************************************************ //
  getTransactions2 = class(getTransactions)
  private
  published
  end;



  // ************************************************************************ //
  // XML       : getTransactionsResponse, global, <element>
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // Info      : Wrapper
  // ************************************************************************ //
  getTransactionsResponse2 = class(getTransactionsResponse)
  private
  published
  end;

  Array_Of_VoucherTransaction = array of VoucherTransaction;   { "https://webmethods.someurl.com/TopUpServices/webServices/Voucher"[GblUbnd] }


  // ************************************************************************ //
  // XML       : ArrayOfVoucherTransaction, global, <complexType>
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // ************************************************************************ //
  ArrayOfVoucherTransaction = class(TRemotable)
  private
    FArrayOfVoucherTransactionItem: Array_Of_VoucherTransaction;
    function  GetArrayOfVoucherTransactionItem(Index: Integer): Array_Of_VoucherTransaction;
    procedure SetArrayOfVoucherTransactionItem(Index: Integer; const AArray_Of_VoucherTransaction: Array_Of_VoucherTransaction);
  public
    function   GetVoucherTransactionArray(Index: Integer): VoucherTransaction;       
    procedure  SetVoucherTransactionArray(Index: Integer; const Item: VoucherTransaction);
    function   GetVoucherTransactionArrayLength: Integer;
    procedure  SetVoucherTransactionArrayLength(Len: Integer);

    property   VoucherTransactionArray[Index: Integer]: VoucherTransaction read GetVoucherTransactionArray write SetVoucherTransactionArray; default;
    property   Len: Integer read GetVoucherTransactionArrayLength write SetVoucherTransactionArrayLength;
  published
    property ArrayOfVoucherTransactionItem: Array_Of_VoucherTransaction  Index (IS_UNBD or IS_UNQL) read GetArrayOfVoucherTransactionItem write SetArrayOfVoucherTransactionItem;
  end;


  // ************************************************************************ //
  // Namespace : https://webmethods.someurl.com/TopUpServices/webServices/Voucher
  // soapAction: TopUpServices_webServices_Voucher_Binder_%operationName%
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : document
  // binding   : TopUpServices_webServices_Voucher_Binder
  // service   : Voucher
  // port      : TopUpServices_webServices_Voucher_Port
  // URL       : https://webmethods.someurl.com:443/ws/TopUpServices.webServices:Voucher
  // ************************************************************************ //
  Voucher_PortType = interface(IInvokable)
  ['{DCE754E5-4B05-3C9B-8078-D4C2BB3F12B4}']

    // Cannot unwrap: 
    //     - Input element wrapper name does not match operation's name
    //     - More than one strictly out element was found
     function  getTransactions(const parameters: getTransactions2): getTransactionsResponse2; stdcall;

   end;

function GetVoucher_PortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): Voucher_PortType;


implementation
  uses SysUtils;

function GetVoucher_PortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): Voucher_PortType;
const
  defWSDL = 'https://webmethods.someurl.com/ws/TopUpServices.webServices:Voucher?WSDL';
  defURL  = 'https://webmethods.someurl.com:443/ws/TopUpServices.webServices:Voucher';
  defSvc  = 'Voucher';
  defPrt  = 'TopUpServices_webServices_Voucher_Port';
var
  RIO: THTTPRIO;
begin
  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 Voucher_PortType);
    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;


constructor getTransactions.Create;
begin
  inherited Create;
  FSerializationOptions := [xoLiteralParam];
end;

function getTransactions.Getdate_from(Index: Integer): string;
begin
  Result := Fdate_from;
end;

procedure getTransactions.Setdate_from(Index: Integer; const Astring: string);
begin
  Fdate_from := Astring;
end;

function getTransactions.Getdate_to(Index: Integer): string;
begin
  Result := Fdate_to;
end;

procedure getTransactions.Setdate_to(Index: Integer; const Astring: string);
begin
  Fdate_to := Astring;
end;

constructor getTransactionsResponse.Create;
begin
  inherited Create;
  FSerializationOptions := [xoLiteralParam];
end;

function getTransactionsResponse.GetvoucherTransactions(Index: Integer): ArrayOfVoucherTransaction;
begin
  Result := FvoucherTransactions;
end;

procedure getTransactionsResponse.SetvoucherTransactions(Index: Integer; const AArrayOfVoucherTransaction: ArrayOfVoucherTransaction);
begin
  FvoucherTransactions := AArrayOfVoucherTransaction;
end;

function VoucherTransaction.GetGLOBAL_SERIAL_NUMBER(Index: Integer): string;
begin
  Result := FGLOBAL_SERIAL_NUMBER;
end;

procedure VoucherTransaction.SetGLOBAL_SERIAL_NUMBER(Index: Integer; const Astring: string);
begin
  FGLOBAL_SERIAL_NUMBER := Astring;
end;

function VoucherTransaction.GetDATE_CREATED(Index: Integer): string;
begin
  Result := FDATE_CREATED;
end;

procedure VoucherTransaction.SetDATE_CREATED(Index: Integer; const Astring: string);
begin
  FDATE_CREATED := Astring;
end;

function VoucherTransaction.GetAMOUNT(Index: Integer): string;
begin
  Result := FAMOUNT;
end;

procedure VoucherTransaction.SetAMOUNT(Index: Integer; const Astring: string);
begin
  FAMOUNT := Astring;
end;

function VoucherTransaction.GetSTATUS(Index: Integer): string;
begin
  Result := FSTATUS;
end;

procedure VoucherTransaction.SetSTATUS(Index: Integer; const Astring: string);
begin
  FSTATUS := Astring;
end;

function VoucherTransaction.GetPIN_CODE(Index: Integer): string;
begin
  Result := FPIN_CODE;
end;

procedure VoucherTransaction.SetPIN_CODE(Index: Integer; const Astring: string);
begin
  FPIN_CODE := Astring;
end;

function VoucherTransaction.GetEXT_REF(Index: Integer): string;
begin
  Result := FEXT_REF;
end;

procedure VoucherTransaction.SetEXT_REF(Index: Integer; const Astring: string);
begin
  FEXT_REF := Astring;
end;

function VoucherTransaction.GetSTORE_ID(Index: Integer): string;
begin
  Result := FSTORE_ID;
end;

procedure VoucherTransaction.SetSTORE_ID(Index: Integer; const Astring: string);
begin
  FSTORE_ID := Astring;
end;

function VoucherTransaction.GetTERMINAL_ID(Index: Integer): string;
begin
  Result := FTERMINAL_ID;
end;

procedure VoucherTransaction.SetTERMINAL_ID(Index: Integer; const Astring: string);
begin
  FTERMINAL_ID := Astring;
end;

function VoucherTransaction.GetEMP_ID(Index: Integer): string;
begin
  Result := FEMP_ID;
end;

procedure VoucherTransaction.SetEMP_ID(Index: Integer; const Astring: string);
begin
  FEMP_ID := Astring;
end;

function VoucherTransaction.GetDATE_INVALIDATED(Index: Integer): string;
begin
  Result := FDATE_INVALIDATED;
end;

procedure VoucherTransaction.SetDATE_INVALIDATED(Index: Integer; const Astring: string);
begin
  FDATE_INVALIDATED := Astring;
end;

function VoucherTransaction.GetEXPIRY_DATE(Index: Integer): string;
begin
  Result := FEXPIRY_DATE;
end;

procedure VoucherTransaction.SetEXPIRY_DATE(Index: Integer; const Astring: string);
begin
  FEXPIRY_DATE := Astring;
end;

function ArrayOfVoucherTransaction.GetVoucherTransactionArray(Index: Integer): VoucherTransaction;
begin
  Result := FArrayOfVoucherTransactionItem[Index];
end;

procedure ArrayOfVoucherTransaction.SetVoucherTransactionArray(Index: Integer; const Item: VoucherTransaction);
begin
   FArrayOfVoucherTransactionItem[Index] := Item;
end;

function ArrayOfVoucherTransaction.GetVoucherTransactionArrayLength: Integer;
begin
  if Assigned(FArrayOfVoucherTransactionItem) then
    Result := System.Length(FArrayOfVoucherTransactionItem)
  else
    Result := 0;
end;

procedure ArrayOfVoucherTransaction.SetVoucherTransactionArrayLength(Len: Integer);
begin
  System.SetLength(FArrayOfVoucherTransactionItem, Len);
end;

function ArrayOfVoucherTransaction.GetArrayOfVoucherTransactionItem(Index: Integer): Array_Of_VoucherTransaction;
begin
  Result := FArrayOfVoucherTransactionItem;
end;

procedure ArrayOfVoucherTransaction.SetArrayOfVoucherTransactionItem(Index: Integer; const AArray_Of_VoucherTransaction: Array_Of_VoucherTransaction);
begin
  FArrayOfVoucherTransactionItem := AArray_Of_VoucherTransaction;
end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(Voucher_PortType), 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Voucher_PortType), 'TopUpServices_webServices_Voucher_Binder_%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(Voucher_PortType), ioDocument);
  InvRegistry.RegisterInvokeOptions(TypeInfo(Voucher_PortType), ioLiteral);
  InvRegistry.RegisterInvokeOptions(TypeInfo(Voucher_PortType), ioSOAP12);
  InvRegistry.RegisterExternalParamName(TypeInfo(Voucher_PortType), 'invalidateVoucher', 'parameters1', 'parameters');
  InvRegistry.RegisterExternalParamName(TypeInfo(Voucher_PortType), 'getTransactions', 'parameters1', 'parameters');
  InvRegistry.RegisterExternalParamName(TypeInfo(Voucher_PortType), 'createVoucher', 'parameters1', 'parameters');
  RemClassRegistry.RegisterXSClass(getTransactions, 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'getTransactions');
  RemClassRegistry.RegisterSerializeOptions(getTransactions, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(getTransactionsResponse, 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'getTransactionsResponse');
  RemClassRegistry.RegisterSerializeOptions(getTransactionsResponse, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(VoucherTransaction, 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'VoucherTransaction');
  RemClassRegistry.RegisterXSClass(getTransactions2, 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'getTransactions2', 'getTransactions');
  RemClassRegistry.RegisterXSClass(getTransactionsResponse2, 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'getTransactionsResponse2', 'getTransactionsResponse');
  RemClassRegistry.RegisterXSInfo(TypeInfo(Array_Of_VoucherTransaction), 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'Array_Of_VoucherTransaction');
  RemClassRegistry.RegisterXSClass(ArrayOfVoucherTransaction, 'https://webmethods.someurl.com/TopUpServices/webServices/Voucher', 'ArrayOfVoucherTransaction');

end.

【问题讨论】:

  • 你的delphi代码是什么样的?
  • XML 中的日期通常采用 yyyy-mm-dd 格式。你试过吗?
  • 这个xml中的日期格式只对dd-mm-yyyy格式有效。
  • 真的很遗憾,对于 dat (w3schools.com/Schema/schema_dtypes_date.asp) 和任何 XSD 数字类型的金额 ( w3schools.com/Schema/schema_dtypes_numeric.asp)。这将使人们公开/使用该网络服务的生活变得更加容易。
  • 你说你得不到回应。这意味着什么?会发生什么,您期望会发生什么?程序会崩溃吗?

标签: c# web-services delphi delphi-2010


【解决方案1】:

使用 SoapUI 使用 WSDL 并创建模拟服务。将您的应用程序指向 SoapUI 模拟服务,您将看到 XML 的样子(SoapUI 将捕获您的请求)。

现在针对原始端点运行 SoapUI(让 SoapUI 创建一个示例请求)并查看它是否有效。如果是这样,请将 SoapUI 请求与您的“盯着并比较”。

或者,使用 RIO 事件在序列化后截取 XML,并转储到文本文件。现在您可以看到生成的 XML。同样,我建议将其粘贴到 SoapUI 中并将其发送到端点,以查看它是否在那里工作。我怀疑它不会,通过将工作请求与您的请求进行比较,您可能会发现问题所在。错误的日期格式、错误的方法名称、缺少命名空间等...

成功完成后,您的“getrr”变量应该保存响应对象。您可能需要遍历响应对象,遍历凭证、交易和 gobbledy-gook 的数组。 Delphi 的调试器将在这里提供帮助——在服务调用后设置断点,您可以检查响应。您可能需要添加一些代码,以便调用不是过程中的最后一件事,或者编译器可能会消除它。即你目前没有对响应对象做任何事情。

【讨论】:

  • 好的,我在 SoapUI 中看到了您的回复。好的。相同的响应应该会命中 Delphi,您可以在 RIO_AfterExecute 方法中拦截它。看看你得到了什么。如果进入 Delphi 的 XML 看起来像在 SoapUI 中的那样,那么您就快到了。请参阅我编辑的响应,其中我谈到了“getrr”响应对象。
  • 我仍然不知道该怎么做,我尝试将 gettrr 分配给各种变体,但无法从中获取任何数据
  • 它不是变体。这是一个getTransactionResponse2。就这样对待它。 IDE 将帮助您探索属性。
  • 我认为 wsdl 单元的导入存在一些问题,因为 getTransactionResponse2 返回为空。
  • 向我们展示 getTransactionResponse2 和相关类型的代理定义。
【解决方案2】:

虽然我并不特别喜欢启用 MapArraysToClasses 选项,但以下说明了如何使用您生成的代理访问服务发回的数据:

procedure TForm33.Button1Click(Sender: TObject);
var
  rr     : voucher17.getTransactions2;
  getrr    : voucher17.getTransactionsResponse2;
  I: Integer;
begin
  rr := getTransactions2.Create;
  try
    rr.date_from := '09.01.2011';
    rr.date_to   := '10.01.2011';

    getrr := GetVoucher_PortType.getTransactions(rr);
    try
      if Assigned(getrr.voucherTransactions) then
      begin
        for I := 0 to getrr.voucherTransactions.Len-1 do
        begin
          ShowMessage(Format('%s, %s, %s', [
              getrr.voucherTransactions[I].GLOBAL_SERIAL_NUMBER,
              getrr.voucherTransactions[I].DATE_CREATED,
              getrr.voucherTransactions[I].AMOUNT]));
        end;
      end;
    finally
      getrr.Free;
    end;
  finally
    rr.Free;
  end;
end;

我选择显示其中三个字段的值。您可能还想阅读其他字段。

我不喜欢 AutoDestroyMembers 被禁用的事实,因为即使上面的代码清理了请求和响应对象,响应中包含的对象数组也不会被正确清理:(。

干杯,

布鲁诺

【讨论】:

  • 谢谢你的好例子。 OP 应该注意,糟糕的命名选择使得 Bruneau 的优雅代码难以阅读。 IMO,而不是 rr 和 getrr,您应该将它们称为 VoucherRequest、VoucherResponse 或 rqst 和 resp。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多