This article explains how to connect to the web services and authenticate a user.
By default credentials are passed in clear text. If this is an issue on a network, please investigate using SSL encryption (HTTPS) and connect to the web service.
The following example uses the included AfterMail.WebService project. This project wraps the creation and setup of the web service connection.
// Connect to the authentication service.
// if we don't set the WebServiceManager.Instance.BaseUrl property first,
// it is assumed to be on localhost.
WebServiceManager.Instance.BaseUrl = string.Format(http://{0}/WebService/,
server);
AfterMailService service = WebServiceManager.Instance.AfterMailService;
// perform the login. NOTE: have a look at the WebServiceManager and how it
// handles the CookieJar / CookieContainer
// If you dont set this, the security doesn't persist.
if (!service.PerformLogin("testuser", "password", "DOMAIN"))
{
//not a lot we can do. Report it to the user.
Console.WriteLine("Can't login. Failing.");
return;
}
To perform this function without using the AfterMail.WebService project, do the following:
AfterMailService service = WebServiceManager.Instance.AfterMailService;
CookieContainer cookieContainer = new CookieContainer();
// The CookieContainer stores the login cookie so we can call methods
// without having to authenticate each time.
service.Url = "http://server/WebServices/AfterMailService.asmx";
service.CookieContainer = cookieContainer;
if (!service.PerformLogin("testuser", "password", "DOMAIN"))
{
//not a lot we can do. Report it to the user.
Console.WriteLine("Can't login. Failing.");
return;
}
NOTE: This article is also available in the Web Services documentation.
© ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center