C# Programmation Réseau: Exemple de connexion à une passerelle DSML à l’aide de SOAP sur HTTP

Author:
 
using System;
using System.Net;
using System.DirectoryServices;
using System.DirectoryServices.Protocols;

public class MainClass {
    public static void Main() {
        Uri uri = new Uri("http://site:8080/dsml3");
        DsmlDirectoryIdentifier identifier = new DsmlDirectoryIdentifier(uri);

        NetworkCredential credentials = new NetworkCredential();
        credentials.UserName = @"username";
        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 + "  ");
                }
            }
        }
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *