I've currently written a proof of concept console application to add a single user to our user profile service, using the SharePoint web services
http://sharepoint/_vti_bin/userprofileservice.asmx.
I have found that reading in a user can use my default network credentials, however the only way I can update or create a user, I have to use the farm system account.
When using the SharePoint dll's (instead of the webservice). I found that all I had to do was ensure my User Profile service had the same permissions as the user running my application. However changing the User Profile service permissions for the web service doesn't make a slightest bit of difference.
I don't wish to hard code (or put in app.config) the username and password of our farm account, I don't mind using a less privedge account, but using a less privedge account how do I give them access so that the web service works?
My code, (if it helps anyone out) is below. Thanks.
private static UserProfileWS.PropertyData[] CreateUserProfile(string accountName)
{
UserProfileWS.PropertyData[] property = null;
try
{
var url = Properties.Settings.Default.UserProfileWSImport_UserProfileWS_UserProfileService;
var myService = new UserProfileWS.UserProfileService();
NetworkCredential nc = new NetworkCredential();
nc.Domain = Properties.Settings.Default.Domain;
nc.UserName = Properties.Settings.Default.UserName;
nc.Password = Properties.Settings.Default.Password;
myService.PreAuthenticate = false;
myService.Credentials = nc;
myService.Url = url;
//If I use either of the lines below instead of NetworkCredentials I get a access denied error when running myservice.CreateUserProfileByAccountName(accountName)
// myService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
//myService.UseDefaultCredentials = true;
property = myService.CreateUserProfileByAccountName(accountName);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return property;
}
