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:
- In Central Administration go to ‘Manage service applications’;
- Select the User Profile Service Application;
- 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’
- 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.