Thema: Delphi Array über SOAP

Einzelnen Beitrag anzeigen

campula

Registriert seit: 17. Jan 2011
6 Beiträge
 
#1

Array über SOAP

  Alt 20. Jan 2011, 00:38
Hallo,

ich experimentiere ein wenig SOAP herum. Inbesondere programmiere ich in Delphi einen Client, der einen Array empfängt. Doch ich scheitere daran, die empfangene Datenstruktur auszulesen.

Die Antwort des Servers siehe so aus:

Code:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.de/soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getAllSitesResponse>
<return xsi:type="SOAP-ENC:Struct">
<getAllSitesResult xsi:type="SOAP-ENC:Struct">
<AllSiteListElement SOAP-ENC:arrayType="SOAP-ENC:Struct[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="SOAP-ENC:Struct">
<idSite xsi:type="xsd:int">1</idSite>
<name xsi:type="xsd:string">siteA</name>
</item>
<item xsi:type="SOAP-ENC:Struct">
<idSite xsi:type="xsd:int">2</idSite>
<name xsi:type="xsd:string">siteB</name>
</item>
</AllSiteListElement>
</getAllSitesResult>
</return>
</ns1:getAllSitesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Meine Unit sieht so aus:

Delphi-Quellcode:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://www.example.de/soap/WebService.wsdl
// Encoding : UTF-8
// Version : 1.0
// (19.01.2011 13:23:21 - 1.33.2.5)
// ************************************************************************ //

unit WebService;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;


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 Borland types; however, they could also
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:AllSiteListElementArray - "http://www.example.de/soap/"
  // !:string - "http://www.w3.org/2001/XMLSchema"

  getAllSitesResult = class; { "http://www.example.de/soap/" }
  AllSiteListElement = class;


  // ************************************************************************ //
  // Namespace : http://www.example.de/soap/
  // Serializtn: [xoLiteralParam]
  // ************************************************************************ //

  AllSiteListElement = class(TRemotable)
  private
      FidSite : integer;
      Fname : string;
  public
// constructor Create; override;
  published
    property idSite : integer read FidSite write FidSite;
    property name : string read Fname write Fname;
  end;



  AllSiteListElementArray = array of AllSiteListElement;

  getAllSitesResult = class(TRemotable)
  public
    FAllSiteListElements: AllSiteListElementArray ;
    constructor Create; override;
  published
    property AllSiteListElements: AllSiteListElementArray read FAllSiteListElements write FAllSiteListElements;
  end;


  /// ******************************************************//



  // ************************************************************************ //
  // Namespace : http://www.example.de/soap/
  // soapAction: http://www.example.de/soap/getAllSites
  // transport : http://schemas.xmlsoap.org/soap/http
  // style : rpc
  // binding : MyWebServiceBinding
  // service : MyWebService
  // port : MyWebServicePort
  // URL : http://www.example.de/soap/server.php
  // ************************************************************************ //
  MyWebServicePortType = interface(IInvokable)
  ['{033B160A-CA94-84C0-538F-78C64F42662C}']
    function getAllSites(const name: WideString): getAllSitesResult; stdcall;
  end;

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


implementation

function GetMyWebServicePortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): MyWebServicePortType;
const
  defWSDL = 'http://www.example.de/soap/WebService.wsdl';
  defURL = 'http://www.example.de/soap/server.php';
  defSvc = 'MyWebService';
  defPrt = 'MyWebServicePort';
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 MyWebServicePortType);
    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 getAllSitesResult.Create;
begin
  inherited Create;
  FSerializationOptions := [xoLiteralParam];
end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(MyWebServicePortType), 'http://www.example.de/soap/', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(MyWebServicePortType), 'http://www.example.de/soap/getAllSites');
// InvRegistry.RegisterInvokeOptions(TypeInfo(MyWebServicePortType), ioLiteral);
  RemClassRegistry.RegisterXSClass(getAllSitesResult, 'http://www.example.de/soap/', 'AllSiteList');
  RemClassRegistry.RegisterSerializeOptions(getAllSitesResult, [xoLiteralParam]);

end.
Wenn ich jetzt den Server abfrage, bekomme ich eine leeres Array zurück:

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
  test : getAllSitesResult;
begin
  test := GetMyWebServicePortType(true).getAllSites('test');
  showmessage(inttostr(high(test.FAllSiteListElements)));

end;
Erkennt irgendwer, was ich falsch mache.

  Mit Zitat antworten Zitat