Einzelnen Beitrag anzeigen

christophspaeth

Registriert seit: 7. Mär 2008
73 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Fehlerbehandlung SOAP Webservice THTTPRio

  Alt 10. Aug 2018, 13:09
Hallo,

bei einem Projekt das noch auf SOAP Webservices aufbaut (und das nicht mal eben so auf REST/JSON umgesetllt werden kann) ist aufgefallen, dass Kommunikationsprobleme (nicht erreichbarer host, nicht auflösbarer Name) anscheinend allesamt mit einem EDOMParseError "XML document must have a top level element. Line: 0" quittiert werden.

Gibt es da eine Möglichkeit das genauer herauszubekommen, also eindeutig ein "Keine Verbindung"? Ein Parse Error Kann ja auch bedeuten, dass ich zwar eine Verbindung bekommen habe, aber nichts oder eben kein XML zurück bekommen habe.

Beispielprogramm (Memo und Button auf Form klatschen) liefert bei mir (Delphi 10.2.3 pro) für alle drei Fälle die oben genannte Exception
Delphi-Quellcode:
implementation

{$R *.dfm}
uses
  InvokeRegistry,
  Soap.SOAPHTTPClient;

type
 IMySoapintf = interface (IInvokable)
  ['{70366272-3F96-4A9D-B87E-70DAFDC55003}']
    function GetData(): string; stdcall;
  end;

function MakeSoapCall(const Url: string): string;
var
  HttpRio: THttpRio;
  soapEngine: IMySoapintf;
begin
  HttpRio := THttpRio.Create(nil);
  try
    soapEngine := HTTPRIO as IMySoapintf;
    HTTPRIO.Url :=Url + '/MyModule/SOAP/IMySoapintf';
  finally
    if soapEngine = nil then
    begin
      FreeAndNil(HttpRio);
    end;
  end;

  if Assigned(SoapEngine) then
  begin
    try
      ShowMessage(soapEngine.GetData());
    except
      on E: Exception do
      begin
        Result := E.ClassName + #13#10#13#10 + E.Message;
      end;
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  urls: TStringList;
begin
  Memo1.Clear();
  urls:= TStringList.Create();
  urls.Add('http://invalid-hostname.sajfsajf'); // invalid or non resolvable hostname
  urls.Add('http://10.0.0.300'); // invalid IP address
  urls.Add('http://10.0.0.30'); // non existing IP address

  for I := 0 to urls.Count -1 do
  begin
    Memo1.Lines.Add(urls[i]);
    Memo1.Lines.Add(MakeSoapCall(urls[I]));
    Memo1.Lines.Add('');
    Memo1.Lines.Add('*****************************');
    Memo1.Lines.Add('');
  end;

end;

initialization
  InvRegistry.RegisterInterface(TypeInfo(IMySoapintf)); {register the interface}
Christoph Späth
  Mit Zitat antworten Zitat