Question

Want some help understanding what I have to do in this situation.
We have user profiles from active directory, but there are some properties that come from an external service which we can get from a WCF service.

What is the best way to approach? I can't seem to understand how the stuff connect, I started doing a Business Data Model in Visual Studio but it's just becoming a big mess in my head.

EDIT
I want sharepoint only to import the data, and the data may be changed in WCF service data source.

Sketch

Was it helpful?

Solution

Peter Holpar has a very good article on this topic as it relates to SharePoint 2010. Generally speaking, it's very much the same in SP 2013. If the property is just going to be populated once from the WCF service and then SharePoint will be the owner of the property (i.e. where people go to update it) then you do not need a BCS model or the sync connection. You could just write a script or console app that does a one time population of the properties in question.

If the WCF service's datasource is still going to be the canonical source for the data, then I would probably manually create the sync connection.

Process - No Code

  1. Create and deploy your BCS model. Your model must contain a property that maps to a unique identifier in AD. I used the SAM Account Name without the domain prefix, i.e. rkaucher not contoso\rkaucher.
  2. Create the sync settings/properties.
    • From the Manage Profile Service page click Manage User Properties.
    • On the User Properties page either find the property you wish to modify or add a new property. In this example I have chosen to edit the Department property. Most of these attributes are pretty self-explanatory.
    • At the bottom of this page ensure that there is nothing listed under Property Mapping for Synchronization. If there is, click remove.

enter image description here

  • Under Add new mapping select your BCS connection for Source data connection and then pick the property from the BCS entity that you wish to map to this user profile property. Don't forget to click add and then OK.

  • Go back to the Manage Profile Service page and select Configure Synchronization Settings. Be sure that Include existing BCS connections for synchronization? is checked as in this image. I didn't do this initially and it took me 30 minutes to figure out what I was doing wrong.

enter image description here

  • Once you have completed that final step you can return to the Manage Profile Service page and click Start Profile Synchronization. Once the sync completed you should see the new property/value on the About me section of the profile page if you have enabled that attribute when you configured the property.

Process - Server OM

Here is some example code for creating a property. This was kind of hard to get working. I created a simple console app to create the property and the connection. One issue that I had before I got it working was that I kept getting a NullReferenceException that was caused by a SecurityException because my account (the account running the code) was not configured in both the administrators and permissions sections of the User Profile Service in Central Admin.

Configure permissions in both places.

At this point, I am so tired my eyes are spinning, so if there are any typos here, feel free to correct them, or add a comment and I will make the correction.

using Microsoft.Office.Server.UserProfiles;
using Microsoft.Sharepoint;
using Microsoft.Sharepoint.Administration;
using System;

//Etc...
//Get a handle on the central admin site collection as site
SpServiceContext context = SPServiceContext.GetContext(site);
UserProfileConfignanager userProfileConfigManager = new UserProfileConfigllanager(context);
UserProfileManager userProfilemanager = new userProfileManager(context);
ProfilePropertytianager propManager = userProfileConfigManager.ProfilePropertylianager;
CorePropertyManager corePropManager = propManager.GetCoreProperties();

CoreProperty coreProp = corePropManager.Create(false);
//The bool above is for isSection, which this is not.
coreProp.Name = "MyBcsFullName";
coreProp.DisplayName = "MY BCS Full Name";
coreProp.Type = PropertyDataType.StringSingleValue;
coreProp.Length = 50;
coreProp.Commit();

//Obviously it’s a user type
ProfileTypePropertyManager typePropManager = propManager.GetProfileTypeProperties(Profilerype.User);
ProfilesubtypePropertyManager subtypePropManager = userProfilemanager.DefaultProfileSubtypeProperties

ProfilesubtypeProperty subProp = subtypePropManager.Create(typePropManager.GetPropertyByName(coreProp.Name));
subProp.IsUserEditable = false;
subProp.DefaultPrivacy = Privacy.Public;
subtypePropManager.Add(subProp);

Connection connection = userProfileConfigManager.ConnectionManager["BCS Properties"];

if (connection != null)
{
    PropertyMapCollection propMapCollection = con.PropertyMapping;
    PropertyMap propMap = propMapCollection[subprop.Name];
    if (propertyMap == null)
    {
        propMapCollection.AddNewMapping(ProfileType.User, subProp.Name, "FullName");
        //The final param is the name of the property in the BCS model.
    }
}

To the right, you will see the property we added.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top