2013-08-25 92 views
1

如何使在IIS访问另一台服务器的Active Directory托管WCF服务如何使WCF服务在IIS访问其他服务器托管的Active Directory

有2台服务器 1 - 应用服务器上的IIS 2的WCF服务托管 - Active Directory服务器 所有我想要做的就是让这个WCF访问活动目录添加,编辑或删除用户

如何使WCF服务访问另一台服务器的同一网络中 我工作的AD内部网门户,用户可以使用他们的Windows凭据“AD”登录并且想要开发管理员ge将用户添加到“AD”

在“AD”中创建用户的wcf服务没有权限执行此操作,我该怎么做?

public bool AddActiveDirectoryUser(ADUser User) 
    { 
     string userLoginName = User.Email.Split("@".ToArray())[0]; 
     // Creating the PrincipalContext 
     PrincipalContext principalContext = null; 
     try 
     { 
      principalContext = new PrincipalContext(ContextType.Domain, ADServer, ADPath.Substring(ADPath.IndexOf("DC")), ADUser, ADPassword); 

     } 
     catch (Exception e) 
     { 
      WriteLog(e); 
      return false; 
     } 


     UserPrincipal usr = UserPrincipal.FindByIdentity(principalContext, userLoginName); 
     if (usr != null) 
     { 
      WriteLog(Enum.LogType.Error, userLoginName + " already exists. Please use a different Username."); 
      return false; 
     } 

     // Create the new UserPrincipal object 
     UserPrincipal userPrincipal = new UserPrincipal(principalContext); 

     if (!string.IsNullOrEmpty(User.LastName) && User.LastName.Length > 0) 
      userPrincipal.Surname = User.LastName; 

     if (!string.IsNullOrEmpty(User.FirstName) && User.FirstName.Length > 0) 
      userPrincipal.GivenName = User.FirstName; 

     if (!string.IsNullOrEmpty(User.Email) && User.Email.Length > 0) 
      userPrincipal.EmailAddress = User.Email; 


     if (!string.IsNullOrEmpty(userLoginName) && userLoginName.Length > 0) 
      userPrincipal.SamAccountName = userLoginName; 

     userPrincipal.SetPassword("123456"); 

     userPrincipal.Enabled = true; 
     userPrincipal.PasswordNeverExpires = true; 

     try 
     { 
      userPrincipal.Save(); 

//这里它抛出一个异常访问被拒绝!!!!?

 } 
     catch (Exception e) 
     { 
      WriteLog(e); 
      return false; 
     } 
     return true; 
    } 
+2

和你的代码?你尝试过什么吗?尝试中的任何错误? – Gonzix

+0

请检查更新 – ATeba

+0

ADUser,ADPassword ...你是从哪里得到的?你有没有试过用这些证书连接到AD?如果没有,请下载apache目录studio尝试连接 – Gonzix

回答