title: Domain.GetDomain(...) fails when called from a web service
body: <p>I have the following code in a class that is called from a web service:</p>
  
  <pre><code>NetworkCredential credentials = new NetworkCredential("user", "password");
  
  connection = new LdapConnection("domain");
  connection.Bind(credentials);
  
  DirectoryContext directoryContext = 
      new DirectoryContext(DirectoryContextType.Domain, "domain");
  
  //  This call returns a domain object with unreadable properties
  Domain domain = Domain.GetDomain(directoryContext);
  </code></pre>
  
  <p>If I instantiate the class directly, all is well, I have a valid domain object that I can work with.  If I go through the web service, the domain object is created, but most of the properties throw exceptions, e.g.:</p>
  
  <pre><code>'domain.Children' threw an exception of type ActiveDirectoryOperationException
  </code></pre>
  
  <p>I have impersonation enabled and am explicitly setting the credentials before calling the web service.  Examining <code>Thread.CurrentPrincipal.Identity.Name</code> on the web service side shows the username of the credentials I've explicitly set. </p>
  
  <p>If I look at <code>Request.LogonUserIdentity</code>, I have the following properties:</p>
  
  <pre><code>Name:  "domain\\username"  (is correct)
  ImpersonationLevel:  Impersonation
  IsAnonymous:  false
  IsAuthenticated:  true
  AuthenticationType:  NTLM
  </code></pre>
  
  <p>Anonymous access is disabled (enabling it makes no difference), and 'Basic Authentication' and 'Integrated Windows Authentication' are both checked.  The web service is running under IIS 5.1 on my development box. </p>
  
  <p>The code that calls the web service, resulting in a failed call to Domain.GetDomain():</p>
  
  <pre><code>MyServiceProxy proxy = new MyServiceProxy ();
  
  CredentialCache credCache = new CredentialCache();
  NetworkCredential netCred = new NetworkCredential(user, password, domain);
  credCache.Add(new Uri(proxy.Url), "Ntlm", netCred);
  proxy.Credentials = credCache;
  
  proxy.MethodCall();
  </code></pre>
  
  <p>The code that calls directly and succeeds:</p>
  
  <pre><code>MyService myService = new MyService();
  myService.MethodCall();
  </code></pre>
  
  <p>Any ideas why calls to Active Directory would fail when made in the context of a web service?  And again, the call doesn't fail per se... it returns a domain object with unreadable properties.  </p>
  
  <p>Thanks in advance!</p>