Reading profile properties in SharePoint 2010

One way to read profile properties in SharePoint 2010 from client side is to consume “userprofileservice.asmx”. Many of the developers created Ajax calls to the service using jQuery or other libraries, which is fine. But there is also an easier to do this. SharePoint 2010 is based on ASP.NET web forms technology and profile service is Ajax enabled, which means we can get the data using only what is already built-in without anything else.

The base of client side web forms is asp:ScriptManager control. It is responsible for loading Microsoft Ajax framework, but not only. Is also able to consume Ajax enabled web services by adding service references to the control.

        <asp:ScriptManager id="ScriptManager" runat="server" enablepagemethods="false" enablepartialrendering="true" enablescriptglobalization="false" enablescriptlocalization="true">
        	<asp:ServiceReference Path="/_vti_bin/userprofileservice.asmx" />

Following the example above, you add actually a reference to “userprofileservice.asmx”. To be clearer, this is translated into client side by loading a JavaScript file from “/_vti_bin/ userprofileservice.asmx” location. If you analyse the JavaScript file, you can see it contains all the classes you need to work with profiles and the main class is called “Microsoft.Office.Server.UserProfiles.UserProfileService”. And to have an example to start with, I am posting here how you can read a profile.

var service = new Microsoft.Office.Server.UserProfiles.UserProfileService();
service.GetUserProfileByName('DOMAIN\\Account', function(profileData) {
    // Do someething with profileData object
}, function(err) {
    // Alert error message
}, null);

Some things I need to mention here. Do not use this method in SharePoint Online. SOAP services are deprecated and there is no guarantees the service will remain there on next updates. However, SharePoint 2010 is an old version and I do not expect the profile service to be removed. So, I would say is safe to use it.