What I am trying to do:
Create a web service
that allows cascading input
for an Infopath form, that queries Active Directory
What I have accomplished:
User has two drop down lists:
1) picking a filtered distribution group, from a list of distribution groups via LDAP AD Query
2) picking a member from that chosen distribution group.
Below is the code I have used to query my Active Directory.
The first WebMethod
Using LDAP it looks at the Distribution Lists OU, filters out all Distribution
Lists beginning with "_Sales -" puts them all in a dataset column, creates a second
dataset column with a new "display name" for that Distribution list (display
name strips off the "_Sales - ", to make it more user friendly)
The second WebMethod
This is supposed to take the group chosen by the first WebMethod
and show the members of that group.
Currently the first WebMethod works fine, the second is what I am having problems with.
When I publish it to an IIS site I can put the name of any distribution list in the query,
and the names of the members of the at Distribution group appear, but how do I pass that
chosen group from the first Web Method in InfoPath?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.DirectoryServices;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public DataSet GetGroupsDL()
{
DataSet ds;
ds = new DataSet();
DataTable dt;
dt = new DataTable();
DataColumn c1 = new DataColumn();
c1.DataType = Type.GetType("System.String");
c1.ColumnName = "groupName";
dt.Columns.Add(c1);
DataColumn c2 = new DataColumn();
c2.DataType = Type.GetType("System.String");
c2.ColumnName = "groupDisplay";
dt.Columns.Add(c2);
try
{
DirectoryEntry thisGroup = new DirectoryEntry(".com/CN=Distribution">LDAP://<mydomain>.com/CN=Distribution Lists,CN=Users,DC=<my domain>,DC=com", "domain_user", "<domain password>");
foreach (DirectoryEntry groupName in thisGroup.Children)
{
if (groupName.Name.StartsWith("CN=_Sales - "))
{
DataRow row = dt.NewRow();
row["groupDisplay"] = groupName.Name.Substring(12);
row["groupName"] = groupName.Name.Substring(3);
dt.Rows.Add(row);
}
}
ds.Tables.Add(dt);
return ds;
}
catch (Exception e)
{
return null;
}
}
// Now how do I take the group chosen from the above LDAP Query and
// pass that group name to the next Web Method?
// Is there a better way?
[WebMethod]
public DataSet GetGroupUsers(string ADInfoDistGroup)
{
DataSet ds;
ds = new DataSet();
DataTable dt;
dt = new DataTable();
DataColumn c1 = new DataColumn();
c1.DataType = Type.GetType("System.String");
c1.ColumnName = "userName";
dt.Columns.Add(c1);
try
{
DirectoryEntry thisGroup = new DirectoryEntry(".com/CN">LDAP://<MyDomain>.com/CN=" + ADInfoDistGroup + ",CN=Distribution Lists,CN=Users,DC=<Mydomain>,DC=com", "<domain_user>", "<domain_password>");
foreach (string userName in thisGroup.Properties["member"])
{
string[] pieces = userName.Split(',');
int i;
for (i = 0; i < pieces.Length; i++)
{
if (pieces[i].StartsWith("CN="))
{
DataRow row = dt.NewRow();
row["userName"] = pieces[i].Substring(3);
dt.Rows.Add(row);
break;
}
}
}
ds.Tables.Add(dt);
return ds;
}
catch (Exception e)
{
return null;
}
}
}
I'll admit I'm a rookie at InfoPath and C# (but I've been doing AD, LDAP, etc for years....). I'm not sure if the following post can help http://sharepointrookie.wordpress.com/2008/07/13/display-site-members-from-ad-groups/ me accomplish what I am trying to do - I'm not a code juggernaut by any means. If anyone can reference any existing code on how to pass data from one webmethod to the next - I'm assuming thats what i need - it would be a great help.
MrMMills
[email protected]