Thema: Delphi SOAP Login (einmalig)

Einzelnen Beitrag anzeigen

Heffalump

Registriert seit: 3. Aug 2005
278 Beiträge
 
RAD-Studio 2009 Ent
 
#5

Re: SOAP Login (einmalig)

  Alt 2. Dez 2008, 23:01
Hallo,

nun, ich nutze nicht das von Dir verwendete Ereignis, sondern das OnWinInetError. TConnection ist eine eigene Klasse, in der ich die Infos für Zugang zum Webservice und eventuellen Proxy speichere und zur Zurverfügungstellung der OnWinInetError Funktion.

Das gibt mir die Möglichkeit, das ich mit dem Start des Programmes bereits die entsprechenden Informationen abfragen kann und erst verwenden muss, wenn der Webserver/Proxy keine integrierte Authentifizierung unterstützt bzw. die Rechte nicht ausreichen. Sollten die Infos falsch sein, dann wird nicht der Standarddialog aufgerufen, sondern das Ereignis abgefangen und mit einem eigenen Dialog abgefragt.


Delphi-Quellcode:
function TConnection.OnWinInetError(LastError: LongWord;
  Request: Pointer): LongWord;
var P: Pointer;
    Status, Len, Index: LongWord; //DWord;

begin
  Len := SizeOf(Status);
  Index := 0;

HttpQueryInfo(Request, HTTP_QUERY_STATUS_CODE or HTTP_QUERY_FLAG_NUMBER,
    @Status, Len, Index);

case Status of
  HTTP_STATUS_DENIED :
    begin
      if Self._FirstAuthCall then
        begin
          InternetSetOption(Request,INTERNET_OPTION_USERNAME,@Self._UserName[1],System.Length(Self._UserName)*2);
          InternetSetOption(Request,INTERNET_OPTION_PASSWORD,@Self._UserPassword[1],System.Length(Self._UserPassword)*2);
          Self._FirstAuthCall := False;
          Result := ERROR_INTERNET_FORCE_RETRY;
        end
      else
        begin
          if Self.ShowWebServiceDialog then
            begin
            InternetSetOption(Request,INTERNET_OPTION_USERNAME,@Self._UserName[1],System.Length(Self._UserName)*2);
            InternetSetOption(Request,INTERNET_OPTION_PASSWORD,@Self._UserPassword[1],System.Length(Self._UserPassword)*2);
            Result := ERROR_INTERNET_FORCE_RETRY;
            end
          else Result := ERROR_CANCELLED;
        end;
    end;
  HTTP_STATUS_PROXY_AUTH_REQ :
    begin
      if Self._FirstProxyAuthCall then
        begin
          InternetSetOption(Request,INTERNET_OPTION_PROXY_USERNAME,@Self._ProxyUserName[1],System.Length(Self._ProxyUserName)*2);
          InternetSetOption(Request,INTERNET_OPTION_PROXY_PASSWORD,@Self._ProxyUserPassword[1],System.Length(Self._ProxyUserPassword)*2);
          Self._FirstProxyAuthCall := False;
          Result := ERROR_INTERNET_FORCE_RETRY;
        end
      else
        begin
          if Self.ShowProxyDialog then
            begin
            InternetSetOption(Request,INTERNET_OPTION_PROXY_USERNAME,@Self._ProxyUserName[1],System.Length(Self._ProxyUserName)*2);
            InternetSetOption(Request,INTERNET_OPTION_PROXY_PASSWORD,@Self._ProxyUserPassword[1],System.Length(Self._ProxyUserPassword)*2);
            Result := ERROR_INTERNET_FORCE_RETRY;
            end
          else Result := ERROR_CANCELLED;
        end;
    end;
  else
    begin
    Result := InternetErrorDlg(GetDesktopWindow(), Request, LastError,
                                     FLAGS_ERROR_UI_FILTER_FOR_ERRORS or
                                     FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS or
                                     FLAGS_ERROR_UI_FLAGS_GENERATE_DATA, P);
    end;
  end;
end;
  Mit Zitat antworten Zitat