Kirk Evans Blog

.NET From a Markup Perspective

Get Social Data from SharePoint via Web Service

Get Social Data from SharePoint via Web Service

Rate This
  • Comments 1

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.

image

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

image

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:

http://<host>/<site>/_vti_bin/SocialDataService.asmx

For my MySite, this means the URL would be:

http://my/sites/kirkevans/_vti_bin/SocialDataService.asmx

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" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="allowImpersonationBehavior">
          <clientCredentials>
            <windows allowedImpersonationLevel="Impersonation" />
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="SocialDataServiceSoap">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm"
                       proxyCredentialType="Ntlm"
                       realm="" />            
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://my/sites/kirkevans/_vti_bin/socialdataservice.asmx"
                binding="basicHttpBinding"
                bindingConfiguration="SocialDataServiceSoap"
                contract="MySiteSocialData.SocialDataServiceSoap"
                behaviorConfiguration="allowImpersonationBehavior"
                name="SocialDataServiceSoap" />
    </client>
  </system.serviceModel>
</configuration>

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 = 
                System.Net.CredentialCache.DefaultNetworkCredentials;

            string[] taggedItems =  
                proxy.GetTagUrlsOfUserByKeyword("Newsletter","sharepoint\\kirkevans");
            foreach (var item in taggedItems)
            {
                Console.WriteLine(item);                
            }
        }
    }
}

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

image

Summary

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!

  • Great article! Have you checked out TechNet Wiki? It would great to get some SharePoint content in community collaboration.

Page 1 of 1 (1 items)
Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
Translate This Page
Search
Archive
Archives