Using serviceConnectionPoints

  • Thread starter Thread starter ssg31415926
  • Start date Start date
S

ssg31415926

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.
 
ssg31415926 said:
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.
 
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 <ENTER> to 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 <ENTER> to 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.
 
If you've got a minute, how can I tell what is COM+ and what isn't?
E.g. one of the MSDN SCP pages refers to using DnsQuery:
http://msdn2.microsoft.com/en-us/library/ms682016.aspx Is this COM+?
Is there somewhere I can look to find out how to use it in my C# code?

Regards

SSG
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 <ENTER> to 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 <ENTER> to 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.
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.
 
ssg31415926 said:
If you've got a minute, how can I tell what is COM+ and what isn't?
E.g. one of the MSDN SCP pages refers to using DnsQuery:
http://msdn2.microsoft.com/en-us/library/ms682016.aspx Is this COM+?
Is there somewhere I can look to find out how to use it in my C# code?

Regards

Note that I didn't say COM+, I said COM.
The Active Directory access provider is implemented as a COM server, and exposed to the
"clients" as a set of COM interfaces called the "Active Directory Service Interfaces" (ADSI)
, one of the interfaces is IDirectoryObject another one is IDirectorySearch. The clients can
be implemented using native C++ or automation- compliant language clients like VB, VBScript,
managed code can use the the interfaces by means of the wrapper classes implemented by the
System.DirectoryServices classes.
Start here for more detailed info:
<http://msdn2.microsoft.com/en-us/library/aa746434.aspx>
..NET V2 also contains a lower level wrapper API set, accessible through the
System.DirectoryServices.Protocols namespace classes, these classes wrap the LDAP protocol
"C style" API set , which makes it possible to access the LDAP store from managed code
without passing through the ADSI provider interface.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top