Quick Start (Base64): Authenticating a user using the web service API

The following C# .NET code example authenticates a user. (See Authenticating Users.)

/** 
    * Ensure that you create a .NET project that uses  
    * MS Visual Studio 2008 and version 3.5 of the .NET 
    * framework. This is required to invoke a  
    * LiveCycle service using MTOM. 
    *      
    * For information, see "Invoking LiveCycle using MTOM" in Programming with LiveCycle   
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
 
//A reference to the AuthorizationManager service 
using AuthenticateUsers.ServiceReference1; 
 
namespace AssignRoles 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
 
               try 
               { 
                   //Create an AuthorizationManagerServiceClient object 
                   AuthenticationManagerServiceClient amClient = new AuthenticationManagerServiceClient(); 
                   amClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/AuthenticationManagerService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b1 = (BasicHttpBinding)amClient.Endpoint.Binding; 
                   b1.MessageEncoding = WSMessageEncoding.Mtom; 
                   amClient.ClientCredentials.UserName.UserName = "administrator"; 
                   amClient.ClientCredentials.UserName.Password = "password"; 
                   b1.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b1.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b1.MaxReceivedMessageSize = 2000000; 
                   b1.MaxBufferSize = 2000000; 
                   b1.ReaderQuotas.MaxArrayLength = 2000000; 
 
                   // Authenticate the user 
                   String username = "wblue"; 
                   string password = "password"; 
                   char[] passwordchars = password.ToCharArray(); 
                   byte[] passwordbytes = new byte[passwordchars.Length]; 
                   for (int i = 0; i < passwordchars.Length; i++) 
                       passwordbytes[i] = (byte)(passwordchars[i]); 
                   AuthResult authResult = amClient.authenticate(username, passwordbytes); 
 
                   //Get User information 
                   User theUser = authResult.authenticatedUser; 
                   Console.WriteLine(theUser.canonicalName + " was succesfully authenticated."); 
     
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace); 
               } 
           } 
       } 
} 
 

// Ethnio survey code removed