title: Determine if a WebService is available or has valid url?
body: <p>How can I check if a WebService is available or has a valid url? </p>
  
  <p>I am using the Delphi Wizard to import and auto generate the neccessary WSDL functions.</p>
  
  <p>The functions the wizard has created for me, doesn't throw an exception nor returns a null object if the WSDL or URL is wrong. Only when I call a function of the returned WSDL class, it throws an strange exception, that the XML-String has not a valid "text/html" style.</p>
  
  <p>Here is the auto generated WSDL function:</p>
  
  <pre><code>function GetcheckVatPortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): checkVatPortType;
  const
    defWSDL = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
    defURL  = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService';
    defSvc  = 'checkVatService';
    defPrt  = 'checkVatPort';
  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 checkVatPortType);
      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;
  
    // ************************************************************************ //
    // Namespace : urn:ec.europa.eu:taxud:vies:services:checkVat
    // Transport : http://schemas.xmlsoap.org/soap/http
    // Stil     : document
    // Verwenden von       : literal
    // Bindung   : checkVatBinding
    // Service   : checkVatService
    // Port      : checkVatPort
    // URL       : http://ec.europa.eu/taxation_customs/vies/services/checkVatService
    // ************************************************************************ //
    checkVatPortType = interface(IInvokable)
    ['{0F901373-2432-32E2-C99D-95B53AE83C79}']
  
      // Entpacken nicht möglich: 
      //     - Mehrere strenge out-Elemente gefunden
      function  checkVat(const parameters: checkVat): checkVatResponse; stdcall;
  
      // Entpacken nicht möglich: 
      //     - Mehrere strenge out-Elemente gefunden
      function  checkVatApprox(const parameters: checkVatApprox): checkVatApproxResponse; stdcall;
    end;
  </code></pre>
  
  <p>If the <code>defWSDL</code> or <code>defURL</code> is invalid or not available, it returns an initiaized <code>checkVatPortType</code> class/interface. Afterward calling a function (<code>checkVatPortType.checkVat</code>)  on that returned interface, I get the strange exception.</p>
  
  <p>That means, if the WebService is not available the user gets a message that the "XML-String has not a valid "text/html" format". Which doesn't describe the problem.</p>