Question

Is it possible to get two User Profiles service application

  • 1). User profile service1
  • 2). User profile service2

I have some code which only fetches the Ist User profile service application but not the second one. How can I access the 2nd User profile Service application using code?

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

Note: For some reason both User Profiles Service applications are provision on same SharePoint farm.

Note: No out of the box sync is used for User profiles.

Was it helpful?

Solution

If you are having two User profile aervice applications in your farm then you need to create one custom connection group for each Web application in the farm. Then, you can change the each User profile service application to be associated with different Web application. It can be done by changing the service applications that are included in the Default service application connection group. In the code, use url of each Web application to get UserProfileManager of each User profile service application

OTHER TIPS

Though I agree that having 2 user profile services on a farm is a little nutty, hopefully your site only has 1 associated with it. You can GetContext on a SPSite object, instead of Default, which should get you the UPS associated to that site. If there's 2 associated... well... I'll have to dig in some more. Let me know if this works.

User Profile Service application will have it's proxy. This will let you distinguish these two services. Assign each proxy to a different proxy group (one could stay in the default group) and second you could assign to 'MyCustomGroup'. This is how you can create it.

New-SPServiceApplicationProxyGroup –Name MyCustomGroup

Now you can go to Central Administration->Application Management->Configure service application associations and assign your new proxy group to the web application. Assign one of the User Profile Service applications proxies to it. And now you are ready to roll.

And this is how you can retrieve Service application context using custom proxy group name.

 SPServiceApplicationProxyGroup applicationProxyGroup =   SPFarm.Local.ServiceApplicationProxyGroups["MyCustomGroup"];
 SPServiceContext serviceContext = SPServiceContext.GetContext(applicationProxyGroup, SPSiteSubscriptionIdentifier.Default);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top