R
Robert Iver
Hello fellow developers,
I'm hoping someone out there can steer me down the right path
with this little conundrum I have, because I am getting frustrated more
and more by the minute. I have a feeling it has something to do with
security/authentication, but I don't know where to start on tackling
it. Here's my scenario:
I'm writing a app that will go onto Pocket PC devices (v2003
SE) that will allow members of our sales team to look up information on
items and run reports. One of the requirements is that they have to be
able to print out those reports after they run them, and they can't lug
printers around with them everywhere. So, I started writing a
webservice with a couple of different methods that would allow the
sales team to select a computer, and then based on their selection,
select a printer to print to.
I'm using the System.DirectoryServices namespace to get a list
of computers from the Sales OU and then populate my combo box for the
sales people to select from. Then I'm using the System.Management
namespace to get all the printers attached to that computer.
Well, it's not working....in my attempts to fix the problem, I
built a VERY simple Windows app that simply takes the webservice code
and runs it locally and it works perfectly.
The problem comes when I'm trying to run the
webservice.....I've posted the code for the webservice below, so feel
free to look at it and see if you can figure out what's going on. Let
me know if you have questions....
<code>
[WebMethod]
public String[] GetComputers(String[] OrganizationalUnits) {
String[] finishedArrayofStrings = null;
DirectoryEntry searchRoot = null;
DirectorySearcher searchForComputers = null; // all null so
can access inside foreach loops
SearchResultCollection searchResults = null;
foreach(String ou in OrganizationalUnits) {
searchRoot = new DirectoryEntry("LDAP://OU=" + ou +
",DC=<basedomainname>,DC=com", "username", "password",
AuthenticationTypes.Secure);
searchForComputers = new DirectorySearcher(searchRoot);
searchForComputers.Filter =
"(&(objectCategory=computer)(name=*))";
searchResults = searchForComputers.FindAll();
foreach(SearchResult s in searchResults){
String temp_string = s.Path.ToString();
String[] temp_string_array = temp_string.Split(',');
// grab just the computer name and leave off the rest
_computerNames.Add(temp_string_array[0].Substring(10,
(int)temp_string_array[0].Length - 10));
}
}
int i = 0;
finishedArrayofStrings = new String[_computerNames.Count];
while (i <= _computerNames.Count) {
finishedArrayofStrings = _computerNames.ToString();
i++;
}
return finishedArrayofStrings;
</code>
I'm hoping someone out there can steer me down the right path
with this little conundrum I have, because I am getting frustrated more
and more by the minute. I have a feeling it has something to do with
security/authentication, but I don't know where to start on tackling
it. Here's my scenario:
I'm writing a app that will go onto Pocket PC devices (v2003
SE) that will allow members of our sales team to look up information on
items and run reports. One of the requirements is that they have to be
able to print out those reports after they run them, and they can't lug
printers around with them everywhere. So, I started writing a
webservice with a couple of different methods that would allow the
sales team to select a computer, and then based on their selection,
select a printer to print to.
I'm using the System.DirectoryServices namespace to get a list
of computers from the Sales OU and then populate my combo box for the
sales people to select from. Then I'm using the System.Management
namespace to get all the printers attached to that computer.
Well, it's not working....in my attempts to fix the problem, I
built a VERY simple Windows app that simply takes the webservice code
and runs it locally and it works perfectly.
The problem comes when I'm trying to run the
webservice.....I've posted the code for the webservice below, so feel
free to look at it and see if you can figure out what's going on. Let
me know if you have questions....
<code>
[WebMethod]
public String[] GetComputers(String[] OrganizationalUnits) {
String[] finishedArrayofStrings = null;
DirectoryEntry searchRoot = null;
DirectorySearcher searchForComputers = null; // all null so
can access inside foreach loops
SearchResultCollection searchResults = null;
foreach(String ou in OrganizationalUnits) {
searchRoot = new DirectoryEntry("LDAP://OU=" + ou +
",DC=<basedomainname>,DC=com", "username", "password",
AuthenticationTypes.Secure);
searchForComputers = new DirectorySearcher(searchRoot);
searchForComputers.Filter =
"(&(objectCategory=computer)(name=*))";
searchResults = searchForComputers.FindAll();
foreach(SearchResult s in searchResults){
String temp_string = s.Path.ToString();
String[] temp_string_array = temp_string.Split(',');
// grab just the computer name and leave off the rest
_computerNames.Add(temp_string_array[0].Substring(10,
(int)temp_string_array[0].Length - 10));
}
}
int i = 0;
finishedArrayofStrings = new String[_computerNames.Count];
while (i <= _computerNames.Count) {
finishedArrayofStrings = _computerNames.ToString();
i++;
}
return finishedArrayofStrings;
</code>