Quick Start (MTOM): Managing users and groups using the web service API

The following C# code example finds a local user and the local group to which the user belongs. (See Managing Users and Groups.)

???/** 
    * 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 DirectoryManager service 
using ManageUsers.ServiceReference1; 
 
 
namespace ManageUsers 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
 
               try 
               { 
                   //Create a DirectoryManagerServiceClient object 
                   DirectoryManagerServiceClient dirManClient = new DirectoryManagerServiceClient(); 
                   dirManClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/DirectoryManagerService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)dirManClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   dirManClient.ClientCredentials.UserName.UserName = "administrator"; 
                   dirManClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b.MaxReceivedMessageSize = 2000000; 
                   b.MaxBufferSize = 2000000; 
                   b.ReaderQuotas.MaxArrayLength = 2000000; 
     
                   //Create a PrincipalSearchFilter to find the user to delete 
                   PrincipalSearchFilter psf = new PrincipalSearchFilter(); 
                   psf.userId = "wblue"; 
                   MyArrayOfUser allUsers = dirManClient.findUsers(psf); 
                   string localUserId = ""; 
                   User theUser = null;  
     
                   //Each element is of type User 
                   int index = allUsers.Count; 
 
                   if (index == 1) 
                   { 
                       //Iterate through the array  
                       for (int i = 0; i < index; i++) 
                       { 
                           // Obtain the principals object identifier 
                           theUser = (User)allUsers[i]; 
                           localUserId = theUser.oid;  
                       } 
 
                       // Find the local group 
                       MyArrayOf_xsd_anyType groupMemberships = theUser.groupMemberships; 
                       string groupId = ""; 
                       Group localGroup = null; 
                       if (groupMemberships.Count > 0) 
                       { 
                           localGroup = (Group)(groupMemberships[0]); 
                           groupId = localGroup.oid; 
                       } 
 
                       // Determine the domain and the group to which the local user belongs 
                       string verifyCanonicalName = theUser.canonicalName; 
                       Domain verifyDomain = dirManClient.findDomain(theUser.domainName); 
                       string verifyDomainName = verifyDomain.domainName; 
                       Group verifyGroup = dirManClient.getDomainAsGroup(verifyDomainName); 
                       string verifyGroupName = verifyGroup.canonicalName; 
 
                       // Print the uniquely identifying information about the user 
                       Console.WriteLine("User name: " + verifyCanonicalName); 
                       Console.WriteLine("Group name: " + verifyGroupName); 
                        Console.WriteLine("Domain names should match: " + verifyDomainName + ", " + theUser.domainName); 
                   } 
 
                   else 
                   { 
                       Console.WriteLine("Principal not found"); 
                   } 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace); 
               } 
           } 
       } 
}