EnablePreAuthentication

Call this function to pre-authenticate the request. This function applies only to webservices that use basic authentication mechanism. This method is available for .NET Web services engine only.

Syntax

conn.EnablePreAuthentication()

Argument Description
conn The name of the SoapConnection object that establishes the connection.

Returns

Long. Valid values are 0 for success and 50 for failure.

Usage

For basic authentication, a request is made to the XML Web service method without initially attempting to authenticate the user.
  • If the XML Web service allows anonymous access, then the XML Web service method executes.
  • If anonymous access is disallowed, a 401 HTTP return code is sent to the client.
In response, the proxy class returns the authentication credentials to the Web server. If the client is authenticated and subsequently authorized to access the XML Web service, the XML Web service method is executed; otherwise the client is denied access.

To summarize, any call to a Web service's method generates at least one 401 error for basic authentication. This behavior does not work with some older versions of the Apache HTTP server, however, and sends a 500 response if a client does not include credentials on the very first request to the server. This behavior violates the guidance from RFCs 2616 and 2617, which suggests that a server should respond with a 401 to a request that has no Authorization header.

To call Web Services located in older Apache servers, or to decrease the roundtrips to the server which you have trusted in advance, call the EnablePreAuthentication function of SoapConnection before you create the proxy object. When calling this function, the WWW-authenticate header is sent with the first request for basic authentication.