Click here to Skip to main content
15,881,967 members
Articles / Programming Languages / C#

Using Service Connection Points with the .NET Framework

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
18 Sep 2009CPOL2 min read 18.1K   111   8  
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:

C#
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:

C#
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:

C#
_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:

C#
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Germany Germany
Dirk Eisenberg is born in a little town in eastern germany: Eisleben. After his university entrance dimploma he went to the Swabian metropolis Stuttgart. The studies of Information Technologies at th BA Stuttgart started at October 1999 and ended with the degree of information technology engineer in 2002. Since this time he is salaried at a software manufacturer in the system management area. At his job he developed system components in C, C++ and C# on the Microsoft Windows platforms for one of the largest Software Management Suites. Currently Dirk is working as an IT Architect for a leading consulting company in Munich.

Comments and Discussions

 
-- There are no messages in this forum --