Steps to reproduce the sample.
1. Install SPML provider (included with the Active Roles Installation media under \Solutions\SPML Provider) to a computer with IIS.
2. Ensure it works. Open url "http://<computer_host>/ARServerSPML/SPMLProvider.asmx".
3. Create a C# console project.
4. "Add Service Reference...", put url from point 2, and rename the reference to "ArsSPML".
5. Open a file "Program.cs" and put this code.
6. Run the project.
DESCRIPTION
This C# sample code demonstrates how to search for users by Active Roles SPML provider. Users displayName that starts with 'S' or contains 'Admin'.
Note This code may use interfaces from Active Roles ADSI Provider Type Library (EDMLib). Please, add a reference to the Active Roles ADSI Provider Type Library (EDMLib) to your C# project.
CODE
//********************************************************************************
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//
// IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,
// PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.
//*********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
namespace SPMLComplexSearchSample
{
using ArsSPML;
class Program
{
static void Main()
{
// Create request object
var request = new CSearchRequest();
// Find active users with displayName starts with 'S' or contains 'Admin';
var filter = new CQueryFilter();
var isUser = new equalityMatch { name = "objectClass", value = "user" };
var isActive = new isActive();
var isStartsWith = new substrings { name = "displayName", initial = "S" };
var isContains = new substrings { name = "displayName", any = new[] { "Admin" } };
filter.Items = new[] {
new and { Items = new object[] // root condition must be allways single
{
isUser, isActive,
new or { Items = new[] { isStartsWith, isContains} }
} } };
request.query = new CQuery();
request.query.filter = filter;
request.query.basePsoID = new CPSOID1 { ID = "DC=arsdev,DC=msk,DC=qsft" };
request.query.scope = "subTree";
request.query.attributes = CreateAttributes(new[] { "cn", "givenName", "l", "displayName" });
request.returnData = "everything";
// Create web service instance
var webService = new QuestOneActiveRolesSPMLProviderSoapClient();
webService.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
// Send request and get response
var response = webService.search(request);
if (!String.IsNullOrEmpty(response.errorMessage))
Console.WriteLine(response.errorMessage);
else
{
if (response.pso != null)
{
foreach (var pso in response.pso)
{
Console.WriteLine(pso.psoID.ID);
foreach (var attr in pso.data)
{
var value = attr.value.Aggregate(string.Empty, (result, next) => result + next + ";");
Console.WriteLine("{0}: {1}", attr.name, value);
}
Console.WriteLine();
}
}
}
Console.WriteLine("Done.");
Console.ReadKey();
}
static attribute[] CreateAttributes(IEnumerable<string> names)
{
return names.Select(name => new attribute { name = name }).ToArray();
}
}
}
//***** END OF CODE ***************************************************************