Thanks for the reply. Win32, COM+, it's all Greek to me! I guess, in
a couple of years, there might be a "Win32/COM+ for .NET Programmers"
but in the meantime...
Anyway, I've put this together and am posting it here in case it's of
use to anyone else:
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace LocateAServiceUsingAnSCP
{
class Program
{
static void Main(string[] args)
{
string gcPath;
gcPath = GetGlobalCatalogNC();
using (DirectoryEntry gcRoot = new DirectoryEntry("GC://" +
gcPath))
using (DirectorySearcher ds = new DirectorySearcher())
{
//Search the global catalog for objects with a
//keyword which identifies the ADAM instance
ds.SearchRoot = gcRoot;
ds.SearchScope = SearchScope.Subtree;
ds.PageSize = 1000;
//looking for an ADAM instance from the
//Microsoft ADAM Step-by-Step Guide
ds.Filter = "(keywords=partition:O=Microsoft,C=US)";
using (SearchResultCollection src = ds.FindAll())
{
if (src.Count == 0)
{
Console.WriteLine("No results found - " +
"press <ENTERto close this window...");
Console.ReadLine();
return;
}
foreach (SearchResult sr in src)
{
//bind to the Global Catalog entry for the SCP
using (DirectoryEntry gcDirEntry =
sr.GetDirectoryEntry())
{
Console.WriteLine("Global Catalog Entry:
{0}",
gcDirEntry.Path);
string distinguishedName =
gcDirEntry.Properties["distinguishedName"].Value.ToString();
//using the distinguishedName from the GC
entry,
//bind to the SCP object
using (DirectoryEntry ncDirEntry =
new DirectoryEntry("LDAP://" +
distinguishedName))
{
string serviceClassName =
ncDirEntry.Properties["serviceClassName"].Value.ToString();
string serviceDNSName =
ncDirEntry.Properties["serviceDNSName"].Value.ToString();
string serviceDNSNameType =
ncDirEntry.Properties["serviceDNSNameType"].Value.ToString();
object[] objects =
(object[])ncDirEntry.Properties["serviceBindingInformation"].Value;
string[] serviceBindingInformation =
new string[objects.Length];
objects.CopyTo(serviceBindingInformation, 0);
Console.WriteLine("serviceClassName :
{0}",
serviceClassName);
Console.WriteLine("serviceDNSName :
{0}",
serviceDNSName);
Console.WriteLine("serviceDNSNameType:
{0}",
serviceDNSNameType);
foreach (string serviceBindingItem in
serviceBindingInformation)
{
Console.WriteLine("serviceBindingInformation: {0}",
serviceBindingItem);
}
}
}
}
Console.WriteLine("Press <ENTERto close this
window...");
Console.ReadLine();
}
}
}
private static string GetGlobalCatalogNC()
{
string gcPath;
using (DirectoryEntry rootDSE = new
DirectoryEntry("LDAP://RootDSE"))
{
gcPath =
rootDSE.Properties["rootDomainNamingContext"].Value.ToString();
}
return gcPath;
}
}
}
Although it's knocked together to test the concept, rather than written
to be production code, I'd still appreciate any comments as to the way
I've done things.
Willy Denoyette [MVP] wrote:
"ssg31415926" <ne**********@gmail.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
Does anyone have any experience using SCPs (serviceConnectionPoints) in
C#? Specifically, I'm trying to use an SCP to locate a service on a
server, once the service has created the SCP.
I've found some documentation on MSDN (at:
http://msdn2.microsoft.com/en-us/library/ms676925.aspx) but it's all
Win32 stuff which doesn't help me as I started with .NET.
It's not Win32 stuff, it's C++ code that calls ActiveDirectory COM API's. The same can be
achieved by using System.DirectoryServices in .NET. Check MSDN for samples using C# to
access the AD's Global Catalog (GC).
Willy.