2013-08-25 94 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

回答