如何在SharePoint中使用选定的用户配置文件服务

基本上我正在做一个计时器工作来发送从SharePoint userprofile服务获取的birthdayWish电子邮件。 但问题是我在服务器上有多个 userprofile服务。

像1)。 userprofile service1
2)。 userprofile service2
3)。 userprofile service3
4)。 userprofile service4

那么如何使用第二个用户配置文件服务。

这是一些代码,我做了:

SPServiceContext oServiceContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default); UserProfileManager oProfileManager = new UserProfileManager(oServiceContext); 

因此,在SPServiceApplicationProxyGroup.Default中获取第一个用户配置文件。

其中我想使用第二个用户配置文件服务 。 但在默认情况下尝试访问其获取第一个用户配置文件服务并迭代它。

那么如何设置它以使用第二个用户配置文件服务。

我的猜测是你有一个用户配置文件服务实例(UPS)上有多个用户配置文件服务应用程序(UPA)(而不是多个UPS):

 var userAppName = "userprofile service2"; SPFarm farm = SPFarm.Local; SPServiceApplication application; foreach (SPService s in farm.Services) { if(s.TypeName.Contains("User Profile Service")) { //We found UPS foreach(SPServiceApplication app in s.Applications) { if(app.Name == userAppName) application = app; //Here is UPA } } } //Or if you like oneliner (not 100% safe) var x = farm.Services.First(s => s.TypeName.Contains("User Profile Service")) .Applications.FirstOrDefault(app => app.Name == userAppName);