Csharp/C Sharp/Network/Dsml — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
Using DsmlDirectoryIdentifier
using System;
using System.Net;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
public class MainClass {
public static void Main() {
Uri uri = new Uri("http://yourSite/dsml1");
DsmlDirectoryIdentifier identifier = new DsmlDirectoryIdentifier(uri);
NetworkCredential credentials = new NetworkCredential();
credentials.UserName = "yourName";
credentials.Password = "password";
DsmlSoapHttpConnection connection = new DsmlSoapHttpConnection(identifier, credentials);
connection.BeginSession();
string distinguishedname = "yourName";
string ldapFilter = "object=user";
string[] attributes = new string[1];
DirectoryRequest request = new SearchRequest(distinguishedname, ldapFilter, System.DirectoryServices.Protocols.SearchScope.Subtree, null);
DirectoryResponse response = connection.SendRequest(request);
connection.EndSession();
}
}
Using DsmlSoapHttpConnection
using System;
using System.Net;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;
public class MainClass {
public static void Main() {
Uri uri = new Uri("http://yourSite:8080/dsml3");
DsmlDirectoryIdentifier identifier = new DsmlDirectoryIdentifier(uri);
NetworkCredential credentials = new NetworkCredential();
credentials.UserName = @"explorer\cnagel";
credentials.Password = "password";
DsmlSoapHttpConnection dsmlConnection = new DsmlSoapHttpConnection(identifier);
string baseDN = null;
string ldapSearchFilter = "(objectClass=*)";
string[] attributesToReturn = null;
SearchRequest searchRequest = new SearchRequest(baseDN, ldapSearchFilter,System.DirectoryServices.Protocols.SearchScope.Base, attributesToReturn);
SearchResponse searchResponse = (SearchResponse)dsmlConnection.SendRequest(searchRequest);
foreach (SearchResultEntry entry in searchResponse.Entries) {
DirectoryAttribute attribute = entry.Attributes["schemaNamingContext"];
Console.WriteLine(attribute.Name + "=" + attribute[0]);
foreach (DirectoryAttribute attr in entry.Attributes.Values) {
Console.Write(attr.Name + "=");
foreach (object value in attr) {
Console.Write(value + " ");
}
}
}
}
}