I've been doing some EXTENSIVE research into the Ratings Service to try to implement a real-time Up/Down voting system. I found a good article that started me off (I'll post later if anyone wants), but I ran into some issues considering that the ratings
are updated through a timer job. In order to combat that, we figured the best way was to grab all the ratings on the URL (GetRatingsOnUrl) which doesn't rely on the service and counting all ratings of 5 (which would be cast from our up arrow) and post the
total into a column of the item the user is rating.
My first big hurdle came when I figured out that some of the SocialDataService calls require elevated privelges that we aren't willing to give all users. To combat this, I thought the best solution would be to create a seperate WCF service that would Elevate
<%@ ServiceHost Language="C#" Debug="true"
Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, Microsoft.SharePoint.Client.ServerRuntime, Version=188.8.131.52, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ITestService" in both code and config file together.
public interface ITestService
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
int SetVotes(string url, string listName);
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class TestService : ITestService
// To test this service, use the Visual Studio WCF Test client
// set the endpoint to http://<Your server name>/_vti_bin/TestWCF/TestService.svc/m
public int SetVotes(string url, string listName)
int test = 60;
using (SPSite site = new SPSite(url))
using (SPWeb ElevatedWeb = site.OpenWeb())
var item = ElevatedWeb.Lists[listName].Items.GetItemById(GetItemID(url));
test = Convert.ToInt32(item["Votes"]);
var serviceContext = SPServiceContext.GetContext(site);
var uri = new Uri(url);
var ratingManager = new SocialRatingManager(serviceContext);
ElevatedWeb.AllowUnsafeUpdates = true;
test = ratingManager.GetCount(uri);
ElevatedWeb.AllowUnsafeUpdates = false;
private int GetItemID(string url)
int index = url.IndexOf("?");
if (index > 0)
url = url.Substring(index).Remove(0, 1);
var node = HttpUtility.ParseQueryString(url).Get("ID");
I'm not looking for a straight answer for this issue that I provided extremely limited information on, I'd just like to know how I'd go about debugging this situation! If anyone could provide some insight into that for me I'd appreciate it a lot.