5

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

  • What are the fields you want to update from the WCF service? Are they generally static, or change a lot? – Robert Kaucher Feb 5 '14 at 18:09
  • generally static maybe once in a while it will be updated ( manually ) – Opetion Feb 5 '14 at 18:28
  • Updated manually in the WCF service's data source? Or in SharePoint? Do you need a two way sync, is what I am getting at. If SharePoint is ultimately canonical, it's a little less work. – Robert Kaucher Feb 5 '14 at 18:37
  • @RobertKaucher updated manually in the WCF service data source. I want sharepoint only to import the data. For now what i'm doing ( or trying ) is I went to sharepoint designer and created one external content type and created a read list action even through i'm not sure if its made the proper way since I have a couple of warnings. – Opetion Feb 5 '14 at 18:51
  • 1
    I updated my answer with some code and more details. The code was pretty hard to figure out. Glad you got yours working. – Robert Kaucher Feb 16 '14 at 3:44
5

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

  • Updated my question. My data may be updated on the wcf data source. Seems interesting, if you manage to find how to create the sync connection, please update your answer. I'll try to find some more information tonight. Currently going home to rest a bit and tomorrow will continue trying. – Opetion Feb 5 '14 at 19:32
  • Sorry it took a while to reply, the link seems to be really helpful. Still didn't get it to work through, but will update as soon as I get this to work – Opetion Feb 6 '14 at 15:19
  • 1
    For future refence for anyone that try that link if it is not working give permissions to be run at the Business Data Connectivity Service. Not being able to get information doesn't give any error or any information at all. – Opetion Feb 6 '14 at 15:43
  • Congrats! and thanks for updating in case anyone needs. – Opetion Feb 17 '14 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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