Error getting average ratings from social data web service?

Currently I’m working on an application that requires me to retrieve the average social rating for a given document library item. Despite having properly set up the User Profile service application, I would consistently run into the same error when I tried to either access the SocialRatingManager.GetAverage() method from a console application. The following is the stacktrace for this error:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.get_ApplicationProperties()
   at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.get_PartitionIDs()
   at Microsoft.Office.Server.Administration.UserProfileApplicationProxy.IsAvailable(SPServiceContext serviceContext)
   at Microsoft.Office.Server.SocialData.SocialDataManager..ctor(SPServiceContext serviceContext)
   at Microsoft.Office.Server.SocialData.SocialRatingManager..ctor(SPServiceContext serviceContext)
   at ConsoleTest.Program.Main(String[] args) in C:\Projects\ConsoleTest\ConsoleTest\Program.cs:line 38

In addition to attempting to run this from a console application, I also have a _layouts page on which I tried to get the same result, although getting it using SPServices through the Socal Data web service this time. Unfortunately to no avail, as I was getting pretty much the same error there as well (note that the stacktrace points to my console app, since I wanted to access the web service directly to rule out any potential issues in SPServices; there weren’t any, both tests resulted in the same error):

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Object reference not set to an instance of an object.
   at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at ConsoleTest.SocialDataWS.SocialDataService.GetRatingAverageOnUrl(String url) in C:\Projects\ConsoleTest\ConsoleTest\Web References\SocialDataWS\Reference.cs:line 795
at ConsoleTest.Program.Main(String[] args) in C:\Projects\ConsoleTest\ConsoleTest\Program.cs:line 53

After a long investigation using dotPeek to go through the SharePoint assemblies, I noticed a call being made to a WCF service which attempts to initialize the profile property cache. Every time a call was made to this service, the following error would appear in the ULS log:

Exception occured while connecting to WCF endpoint: System.ServiceModel.Security.SecurityAccessDeniedException: Access is denied.

Weird, an “access denied” error even though my account is a farm administrator. Apparently, the service application has a different set of administrators and permissions, which you can set here:

  1. In Central Administration go to ‘Manage service applications’;
  2. Select the User Profile Service Application;
  3. In order to solve the SocialRatingManager error, I had to do the following:
    Click Permissions from the ribbon and add the account you’re using to run the console application, giving it ‘Full Control’
  4. To solve the web service (and SPServices) error, do the following:
    Click Administrators from the ribbon and add your account, giving it ‘Manage Social Data’ permissions.
These settings resolved my issues and I was able to correctly use the service from my page. Hope this helps anyone else running into the same vague errors with the social data service.
Be Sociable, Share!

One thought on “Error getting average ratings from social data web service?

  1. Pingback: Using SPServices and jQuery to include social rating control on _layouts page |

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">