6

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.

4
  • Why would you want two? Should the run on different servers?
    – Benny Skogberg
    Dec 11, 2012 at 14:51
  • It's a requirement for the client to have the two user profiles on same SharePoint farm.
    – Geek
    Dec 11, 2012 at 14:53
  • Note: no out of the box sync is used for User profiles.
    – Geek
    Dec 11, 2012 at 14:54
  • Note: no out of the box sync is used for User propfiles.
    – Geek
    Dec 11, 2012 at 14:54

3 Answers 3

2

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

2
  • It's rather proxy group that is attached to the Web Application, and this is how availability of different Service Applications in Web Application is managed. Dec 14, 2012 at 11:58
  • I did this scenario a long time ago. Thanks for correction Jan 6, 2013 at 16:58
2

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.

1
  • appreciate your help!
    – Geek
    Dec 14, 2012 at 8:43
2

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.