Using Service Connection Points with the .NET Framework
This article describes a way to find, create and update service connection points in the active directory based on the .NET Framework.
Introduction
This article describes a way to find, create and update so called Service Connection Points. I want to start with a short history about I got my knowledge about SCPs.
My colleague Stefan Kuhr gave me a hint on how I can store some availability information in the Active Directory about a small service I wrote. So I identified the basic idea to store connection information behind an active directory object as the best solution for my software.
There are several ways to get the job done in native code based on the com objects of the ADSI interface. More details about this technology will be available in the MSDN library. I invested a little bit of time to get a solution based on the .NET Framework written in C#. The namespace System.DirectoryServices
supports a rich wrapper around the native com objects and will be the right tool for this task.
Background
Service Connection Points are child objects on a specific computer object to populate a specific service information including the access parameters. With the AD Explorer of Microsoft it would be possible to browse this objects, e.g. on the level of the domain controllers. This example will store the dnsServiceName
and the bindingOptions
into the active directory. These settings are available through a common identifier, e.g. a well known GUID.
Using the Code
The code exports the class SvcConnectionPoint
which contains all information about a service and the class SvcConnectionPointMgr
which controls the access on the ad objects. To create a simple SCP, use the following call sequence:
SvcConnectionPointMgr s = new SvcConnectionPointMgr();
SvcConnectionPoint scp = s.CreateConnectionPoint( "MyUniqueSCPId",
"ADSComputerName",
"Name of the SCP",
"DNS Name (URL)",
"Binding Options/Parameters");
The method CreateConnectionPoint
will add a connection point entry to the ads object of the target computer as a child object. The following code will demonstrate this:
DirectoryEntry scp_entry = null;
// open an existing scp
scp_entry = p.Children.Find(adsName);
// create the new child record
if ( null == scp_entry )
scp_entry = p.Children.Add(adsName, "serviceConnectionPoint");
// build our scp object
SvcConnectionPoint scp = new SvcConnectionPoint(scp_entry);
// fill the values
scp.svcKeyword = keyword;
scp.dnsName = dnsName;
scp.svcBinding = bindingOptions;
Every change at an ads object has to be committed explicitly with a call of the method CommitChanges
:
_scp.CommitChanges();
The same procedure is used to read the service connection point information from the Active Directory. To get information about the service searching via LDAP for one or more objects with the specific unique identifier in the property keywords and reading out the right property is necessary. The following code will demonstrate this:
String ldapFilter = "(keywords=" + uuid + ")";
List<String> props = new List<string>();
props.Add("serviceDNSName");
props.Add("serviceBindingInformation");
DirectorySearcher search = null;
if (start != null)
search = new DirectorySearcher(start, ldapFilter);
else
search = new DirectorySearcher(ldapFilter);
search.PropertiesToLoad.AddRange(props.ToArray());
SearchResultCollection src = search.FindAll();
if (src == null)
return null;
The attached archive contains the whole implementation of the described idea. Feel free to try out this approach to populate services in an active directory environment. A very detailed look into SCPs will be available in the MSDN library documentation.
History
- 18th September, 2009: Initial post