Hi all,
I have the following Web Service running:
using System;
using System.Web;
using System.Data;
using System.Text;
using System.Collections;
using System.Diagnostics;
using System.Web.Services;
using System.ComponentModel;
using System.DirectoryServices;
namespace GetADGroupUsersCredentials
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
public class Credentials
{
private string name;
private string account;
private string mail;
public string Name
{
get { return name;}
set { name = value;}
}
public string Account
{
get { return account;}
set { account= value;}
}
public string Mail
{
get { return mail;}
set { mail = value;}
}
}
[WebMethod]
public Credentials[] getUserCredentials()
{
DirectoryEntry group = new DirectoryEntry("LDAP://CN,OU,OU,OU,DC,DC,DC");
StringBuilder sb = new StringBuilder();
//start an ldap filter
sb.Append("(|");
using (group)
{
foreach (string s in group.Properties["member"])
{
sb.AppendFormat("(distinguishedName={0})", s);
}
}
//end the filter
sb.Append(")");
string[] strProperties = new string[]{"cn", "mail", "samaccountname"};
DirectoryEntry searchRoot = new DirectoryEntry("LDAP://dc=corp,dc=huskyims,dc=com");
DirectorySearcher search = new DirectorySearcher(searchRoot, sb.ToString(), strProperties);
SearchResultCollection resultCollection = search.FindAll();
ArrayList al = new ArrayList();
foreach (SearchResult sr in resultCollection)
{
Credentials c = new Credentials();
c.Name = sr.Properties["cn"][0].ToString();
c.Account = sr.Properties["samaccountname"][0].ToString();
c.Mail = sr.Properties["mail"][0].ToString();
al.Add(c);
}
return (Credentials[])al.ToArray(typeof(Credentials));
}
}
}
With this web service I read the eMail address, realname, and samaccount name for each user in a group.
The xml structure I get from the service looks like this:
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfCredentials xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
- <Credentials>
<Name>Real Name(Luxembourg)</Name>
<Account>samaccountname</Account>
<Mail>mail address</Mail>
</Credentials>
- <Credentials>
<Name>real name (Luxembourg)</Name>
<Account>samaccountname</Account>
<Mail>mail address</Mail>
</Credentials>
</ArrayOfCredentials>
Now in IP I populate a DDL with this values. The display name is the Real Name and the value is the samaccount name. The last step with which I am struggeling is that I want to write the third value (mail address) from the user selected via the DDL into another textbox.
Can someone point me to the right direction ?
Thx