When You will try to perform remote call to WebService made in Lotus Domino with access allowed only for authenticated users You will get login screen as an response. It is possible to disable this feature by setting "allow public access" true on WebService design element, but for security reasons it is not recommended. It is possible to send authentication information using two scenarios: Basic Authentication and Cookie Based Authentication.

Basic Authentication
This scenario is quite easy. It requires Internet access in Domino set to Basic Authentication.


// Create WebService proxy class instance
WebReference.WebServiceTestService service = new ConnectDominoWSTest.WebReference.WebServiceTestService();
// Enable pre-authentication
service.PreAuthenticate = true;
// Allow redirection (domino will redirect to logon screen and back to web service)
service.AllowAutoRedirect = true;
// Setting up credentials
service.Credentials = new NetworkCredential("YourUsername", "YourPassword");
// Perform Webservice call
string s = service.HELLOWORLD();


Cookie Based Authentication
Second scenario is more complicated, but thanks to .NET power it is possible to do. It requires Internet access in Domino set to Session-based authentication or Single sign-on.


// Cookie container to store authentication cookie
CookieContainer cookies = new CookieContainer();

// Prepare HTTP request
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("YourServer/names.nsf?login");
request.Method = "POST";
request.AllowAutoRedirect = false;
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = cookies;

// Prepare POST body
string post = "Username=YourUsername&Password=YourPassword";
byte[] bytes = Encoding.ASCII.GetBytes(post);

// Write data to request
request.ContentLength = bytes.Length;
Stream streamOut = request.GetRequestStream();
streamOut.Write(bytes, 0, bytes.Length);
streamOut.Close();

// Get response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

// Check if we are authenticated properly
if ((response.StatusCode == HttpStatusCode.Found) ||
(response.StatusCode == HttpStatusCode.Redirect) ||
(response.StatusCode == HttpStatusCode.Moved) ||
(response.StatusCode == HttpStatusCode.MovedPermanently)) {

// Create WebService proxy class instance
WebReference.WebServiceTestService service = new ConnectDominoWSTest.WebReference.WebServiceTestService();
// Set up authentication cookie
service.CookieContainer = cookies;
// Perform Webservice call
string s = service.HELLOWORLD();
}


In both scenarios it is used WebService proxy class generated from wsdl file.

4 comments:

Thanks, I've been wondering how to do this for quite a while. I wasn't sure it was possible..

December 03, 2009  

Thanks for the post, my problem is - how do I disable form-based and enable basic authentication on Domino for a particular nsf-database?

November 23, 2010  

@Alexander, I am not very experienced Domino Administrator, but I am afraid this is server wide setting... but I am not 100% sure.

November 26, 2010  

Thanks for sharing this post.. Anar .NET Solutions

August 18, 2015  

Newer Post Older Post Home