iisでホストされているwcfサービスを別のサーバーのアクティブディレクトリにアクセスさせる方法
2つのサーバーがあります1-WCFサービスがIISでホストされているアプリケーションサーバー2-アクティブディレクトリサーバー私がしたいのは、このWCFがアクティブディレクトリにアクセスしてユーザーを追加、編集、または削除することだけです
WCF サービスを同じネットワーク内の別のサーバーの AD にアクセスさせる方法 ユーザーが Windows 資格情報「AD」でサインインできるイントラネット ポータルに取り組んでおり、ユーザーを「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;
}