about System.DirectoryServices.SearchResultCollection Class.

  • Thread starter Thread starter hykim
  • Start date Start date
H

hykim

Hello, everyone.

according to MSDN, there is any constructor of
System.DirectoryServices.SearchResultCollection Class.
if I implement DirectorySearcher.FindAll() method by myself, then how can I
instanciate SearchResultCollection Class.
more clearly, a SearchResult object is created, at the inside of FindAll()
method, then how can I put this object into the SearchResultCollection
object. there is any method releated to input operation.

and, SearchResultCollection has a property named "Handle" meaning
DSA_SEARCH_HANDLE, what is it? I have no idea about ADSI.

thanks.
 
according to MSDN, there is any constructor of
System.DirectoryServices.SearchResultCollection Class.

There is no publicly visible constructor, that's what you're saying,
right?
if I implement DirectorySearcher.FindAll() method by myself, then how can I
instanciate SearchResultCollection Class.

First of all, why would you want to? What's wrong with the currently
available FindAll() method? What are you trying to accomplish?

Secondly, since SearchResultCollection is a class without publicly
available constructor, you CANNOT instantiate it yourself - you would
have to re-create that collection class yourself and use that
collection for your own FindAll() call.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
thanks for your attention.

at normal case, using DirectoryServices is good choice. It's no doubt. but
some cases, it's services are seems to be restriced. - maybe, it's possible
that I misunderstand or don't know exactly about DirectoryServices.
I'd like to specify Connection Timeout to the DirectoryEntry object. and, I
want to handle only first page of paged search.

So, I decided to make my own directory services namespace wrapping Win32
LDAP API with Managed C++. my DirectoryEntry and DirectorySearcher classes
works well(not perfect, but I satisfy with it). I'd like to support code
exchangability between System.DirectoryServices and my own
DirectoryServices. So their base classes and interfaces matchs for each
other, exactly.
Other Collection Classes are having Add() method for new item. but, only
SearchResultCollection class don't have any methods for new item.

How can I instaciate SearchResultCollection class form
SearchResult.FindAll() method.

Thanks once more, for reading my poor English. I'm a Korean and I don't
familiar with English.
 
I'd like to specify Connection Timeout to the DirectoryEntry object. and,

Have a look at DirectorySearcher.ClientTimeout or
DirectorySearcher.ServerTimeLimit (not sure which one you want to
limit).
I want to handle only first page of paged search.

Have a look at DirectorySearcher.PageSize
How can I instaciate SearchResultCollection class form
SearchResult.FindAll() method.

You CAN'T - period. There is *NO* publicly visible constructor, so YOU
CANNOT instantiate a SearchResultCollection.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Both DirectorySearcher.ClientTimeout and DirectorySearcher.ServerTimeLimit
are something to do with SEARCH TIMEOUT.
I want to specify CONNECTION TIMEOUT of DirectoryEntry.

DirectorySearcher.PageSize used for specify JUST page size when paged
searches are needed. It's not meaning the possability of paged results
handling. e.g. If I specify DirectorySearcher.PageSize = 500 when perform a
search operation resulting 1500 object, then (maybe) DirectorySearcher
performs this query for three times at ADSI level. like as 500 - 500 -
500 -> 1500. But, I want to handle only first result page and to choose to
perform second search operation or not.

So I decided to make my own DirectoryServices.
I know that there is no publicly visible constructor. so I am concerned
about the concept or the methodolgy of howto instantiate object from a class
whitch doesn't have any publicly visible constructors or methods needed for
object initialization. System.DirectoryServices.DirectorySearcher.FindAll()
method returns System.DirectoryServices.SearchResultCollection. how can do
this? Is it job of SearchResultCollection that generating search results
collection?
 
Both DirectorySearcher.ClientTimeout and DirectorySearcher.ServerTimeLimit
are something to do with SEARCH TIMEOUT.
I want to specify CONNECTION TIMEOUT of DirectoryEntry.

What CONNECTION TIMEOUT ?? You have connection timeouts for database
connections, yes - those need to be set on the ADO.NET SqlConnection
object (or whichever xxxConnection object you use) - that has nothing
to do with the DirectoryEntry of AD.
DirectorySearcher.PageSize used for specify JUST page size when paged
searches are needed. It's not meaning the possability of paged results
handling. e.g. If I specify DirectorySearcher.PageSize = 500 when perform a
search operation resulting 1500 object, then (maybe) DirectorySearcher
performs this query for three times at ADSI level. like as 500 - 500 -
500 -> 1500. But, I want to handle only first result page and to choose to
perform second search operation or not.

Okay, I didn't understand your question then. As far as I know,
there's no built-in functionality for this (explicitly handling only
the "top xxx" results).
I know that there is no publicly visible constructor. so I am concerned
about the concept or the methodolgy of howto instantiate object from a class
whitch doesn't have any publicly visible constructors

The easy answer is: if there is no publicly visible constructor, YOU
CANNOT INSTANTIATE AN OBJECT OF THAT CLASS. Period. No way around it.
System.DirectoryServices.DirectorySearcher.FindAll() method returns
System.DirectoryServices.SearchResultCollection. how can do this?

It's defined in the same namespace as the SearchResultCollection, and
therefore, it can access a protected, internal, or private
constructor.

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
thanks very much ^.^

Your answers for last questions are very helpful for me.
I mean... think about this situation, if a domain controller shut-downed or
it's network cables are unpluged, and some client try to
bind(DirectoryEntry's object needs to connect to that server). then, what
happen? the client maybe waits 20~30 seconds to find out server fault. so I
need Connection Timeout.

I really appreciate your help.

and, I have another question.
what is MVP?
 
The DirectoryEntry object doesn't have a connection time out property because this class is not making any connection (does not call
Bind()).
You can use the ClientTimeout on the DirectorySearcher object instead.

Willy.
 
I mean... think about this situation, if a domain controller shut-downed or
it's network cables are unpluged, and some client try to
bind(DirectoryEntry's object needs to connect to that server). then, what
happen? the client maybe waits 20~30 seconds to find out server fault. so I
need Connection Timeout.

But there is no connection timeout, sorry - you would have to set that
up on the local machine, as part of the machine's setup and/or group
policy, that's not something you're supposed to be fiddling with every
time you try to bind to an AD object.
and, I have another question.
what is MVP?

Microsoft Most Valuable Professional, see:
http://mvp.support.microsoft.com/default.aspx?scid=fh;EN-US;mvpfaqs

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
system.directoryservices.dll!System.DirectoryServices.DirectoryEntry::Bind(b
ool throwIfFail = true) + 0x24d Bytes

system.directoryservices.dll!System.DirectoryServices.DirectoryEntry::Bind()
+ 0x14 Bytes

system.directoryservices.dll!System.DirectoryServices.DirectoryEntry::get_Ad
sObject() + 0xf Bytes

system.directoryservices.dll!System.DirectoryServices.DirectorySearcher::Fin
dAll(bool findMoreThanOne = true) + 0x186 Bytes

system.directoryservices.dll!System.DirectoryServices.DirectorySearcher::Fin
dAll() + 0x15 Bytes
SearchTimeout.exe!SearchTimeout.TEST.Main(string[] args = {Length=0}) Line
10 + 0xa Bytes C#

How do you think about above? It's a dump of call stack. It says that
DirectoryEntry class has at least two private methods named Bind().

You can use the ClientTimeout on the DirectorySearcher object instead.

Okay. Look at this code.

-------------------------------------------------------------------
using System;
using System.DirectoryServices;

class TEST
{
[STAThread]
static void Main(string[] args)
{
DirectoryEntry deRoot = new DirectoryEntry();
DirectorySearcher dsSearcher = new DirectorySearcher();

deRoot.Path= "LDAP://1.1.1.1/cn=Users,dc=mycom,dc=net";
deRoot.AuthenticationType = AuthenticationTypes.ServerBind;

dsSearcher.SearchRoot= deRoot;
dsSearcher.ClientTimeout = TimeSpan.FromSeconds(2);

dsSearcher.FindAll();
}
}

-------------------------------------------------------------------

Is it you said?
At this code, Server IP Address(1.1.1.1) is not exist in the network.
If you try this code, then you can see above call stack easily.

I Would like to specify the time needed to find out [Server Down]. The
sample code spends 20 seconds.
I mentioned about my own DirectoryServices namespace, at the first of my
question history.
It was written with Managed C++, wrapping Win32 LDAP API.
It is the purpose of my own DirectoryServices, that CONNECTION TIMEOUT and
PAGED SEARCH RESULTS HANDLING.
And, I hope to code using System.DirectoryServices can use my own
DirectoryServices without any modification.
So, I decided to make my own DirectoryServices to use same base class and
same interfaces.

According to RFC 2251 "Lightweight Directory Access Protocol (v3)",
connection timeout is not mentioned.
Maybe System.DirectoryServices based on it. And Win32 LDAP API may not
support it, too(I didn't check it, yet).

When I making it, I faced a proplem. DirectorySearcher.FindAll() returns
SearchResultCollection.
It was the start point of my question. Howto generating search results(as
SearchResultCollection) without any public constructors or related methods.
SearchResultCollection doesn't have Add() method.

And now, Marc Scheuner's answer encouraged me. I will check protected
constructor and Win32 LDAP API. But, it's not right now.

thank you, anyway.
 
thanks.

Okay, that is not i want.
And, I tested Win32 LDAP API with ldp.exe. It has a menu for Connection
option.
But, it doesn't works as I wanted. It works same with
System.DirectoryServices.
I will try about it more than now, after study.

Thanks, Marc Scheuner.
 
I didn't say that it did not implement Bind, I did say that the Bind was not called when the Directory object was created,
DirectoryEntry::Bind is called when you call a method like FindAll (and there are many others), Please read your stack dump and
follow the call chain. (... DirectorySearcher::FindAll(bool findMoreThanOne = true) -> DirectoryEntry::get_AdsObject() ->
DirectoryEntry::Bind() ..)

Willy.


hykim said:
system.directoryservices.dll!System.DirectoryServices.DirectoryEntry::Bind(b
ool throwIfFail = true) + 0x24d Bytes

system.directoryservices.dll!System.DirectoryServices.DirectoryEntry::Bind()
+ 0x14 Bytes

system.directoryservices.dll!System.DirectoryServices.DirectoryEntry::get_Ad
sObject() + 0xf Bytes

system.directoryservices.dll!System.DirectoryServices.DirectorySearcher::Fin
dAll(bool findMoreThanOne = true) + 0x186 Bytes

system.directoryservices.dll!System.DirectoryServices.DirectorySearcher::Fin
dAll() + 0x15 Bytes
SearchTimeout.exe!SearchTimeout.TEST.Main(string[] args = {Length=0}) Line
10 + 0xa Bytes C#

How do you think about above? It's a dump of call stack. It says that
DirectoryEntry class has at least two private methods named Bind().

You can use the ClientTimeout on the DirectorySearcher object instead.

Okay. Look at this code.

-------------------------------------------------------------------
using System;
using System.DirectoryServices;

class TEST
{
[STAThread]
static void Main(string[] args)
{
DirectoryEntry deRoot = new DirectoryEntry();
DirectorySearcher dsSearcher = new DirectorySearcher();

deRoot.Path= "LDAP://1.1.1.1/cn=Users,dc=mycom,dc=net";
deRoot.AuthenticationType = AuthenticationTypes.ServerBind;

dsSearcher.SearchRoot= deRoot;
dsSearcher.ClientTimeout = TimeSpan.FromSeconds(2);

dsSearcher.FindAll();
}
}

-------------------------------------------------------------------

Is it you said?
At this code, Server IP Address(1.1.1.1) is not exist in the network.
If you try this code, then you can see above call stack easily.

I Would like to specify the time needed to find out [Server Down]. The
sample code spends 20 seconds.
I mentioned about my own DirectoryServices namespace, at the first of my
question history.
It was written with Managed C++, wrapping Win32 LDAP API.
It is the purpose of my own DirectoryServices, that CONNECTION TIMEOUT and
PAGED SEARCH RESULTS HANDLING.
And, I hope to code using System.DirectoryServices can use my own
DirectoryServices without any modification.
So, I decided to make my own DirectoryServices to use same base class and
same interfaces.

According to RFC 2251 "Lightweight Directory Access Protocol (v3)",
connection timeout is not mentioned.
Maybe System.DirectoryServices based on it. And Win32 LDAP API may not
support it, too(I didn't check it, yet).

When I making it, I faced a proplem. DirectorySearcher.FindAll() returns
SearchResultCollection.
It was the start point of my question. Howto generating search results(as
SearchResultCollection) without any public constructors or related methods.
SearchResultCollection doesn't have Add() method.

And now, Marc Scheuner's answer encouraged me. I will check protected
constructor and Win32 LDAP API. But, it's not right now.

thank you, anyway.
 
It works the same way because the DirectoryServices classes are wrappers arround ADSI (COM interfaces) who are using the LDAP
library wldap32.dll jus like ldp.exe.

What stops you to use the ClientTimeout on the DirectorySearcher object ?

Willy.
 
Back
Top