Kirk Evans Blog

.NET From a Markup Perspective

Get Social Data from SharePoint via Web Service

I am working on a project to create newsletters to send to my customers, and experimenting with a few ways to collect the information so that I can easily author the newsletter later. 

One way that I am experimenting with is to use the Tagging feature of SharePoint 2010.  As I visit different web sites that are external to my farm, I can tag that site with my own URL, which saves the tag and the URL in my profile.  Later, I can view the tags and notes that I have applied.

My idea was to add the Tags and Noteboard shortcut to my favorites bar in IE, making it easy to just click the link to save it to my profile.


When I click the link, I get the following window popup:


Later, I can visit my MySite and see the items that I have tagged.  But how can I use this to possibly automate the generation of a newsletter?  I really don’t want to go back to my MySite and copy and paste everything I tagged. 

One way is to use the SocialData web service in SharePoint 2010.  This service is located at:


For my MySite, this means the URL would be:


There are methods such as GetTagUrlsOfUser, GetTagsOfUser, and GetTagUrlsOfUserByKeyword that we can use to retrieve data.  This makes obtaining the data a simple WCF call.  In Visual Studio 2010, add a service reference to the SocialDataService.asmx endpoint, and then edit the app.config:

<?xml version="1.0" encoding="utf-8" ?>
        <behavior name="allowImpersonationBehavior">
            <windows allowedImpersonationLevel="Impersonation" />
        <binding name="SocialDataServiceSoap">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm"
                       realm="" />            
      <endpoint address="http://my/sites/kirkevans/_vti_bin/socialdataservice.asmx"
                name="SocialDataServiceSoap" />

WCF is talking to an ASMX service, so there are certain aspects of communication that it guesses at.  It correctly guesses that we are using basic HTTP communication, but it cannot infer the details of authentication, we have to provide those details. 

  • WCF has to be told to use impersonation to use the current user’s credentials to access the backend service.  We do this by creating the endpointBehavior. 
  • Our SharePoint site uses NTLM for authentication.  We tell WCF to use NTLM by configuring the HTTP binding.  I also cleaned up the binding configuration a bit to make it easier to read.

Now that we have configured how to talk to the service endpoint and provided security details, the last thing is the easy part… writing the code to call the service.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
    class Program
        static void Main(string[] args)
            MySiteSocialData.SocialDataServiceSoapClient proxy = 
                new MySiteSocialData.SocialDataServiceSoapClient();            
            proxy.ChannelFactory.Credentials.Windows.ClientCredential = 

            string[] taggedItems =  
            foreach (var item in taggedItems)

The result is a list of URLs that I have tagged with the term “Newsletter”:



I am still looking for an easy way to collect URLs and some text about them, and to be able to collect that data to generate a newsletter later.  I am not sure if I will end up using tags and notes or if there is some other way to achieve this, but you’ve got to admit that it’s pretty cool to be able to tag various URLs and retrieve them later!