Working with the TaxonomyClientService: Part 2 – Get the TermSet (and understand it!)

In Part 1 I looked at the structure of our Taxonomy field – which is in fact two fields. We also saw how the TaxonomyField definition has an array of properties related to it too. As a reminder, here’s a screenshot of the XML for it:

These properties are quite important, as they tell us what we need to know to get the correct TermSet for our field.

If you look in the properties you’ll see:

  • SspId – The ID of the Managed Metadata Service containing the TermSet for this field. This ID is also sometimes referred to as the TermStore ID.
  • TermSetId – The ID of the TermSet for this field.

With this information we can use the GetTermSets method of the TaxonomyClientService. (The code below is based on “Working with the Managed Metadata Service Remotely” by Virtosoft.

string clientTimestamps = string.Format("<timeStamp>{0}</timeStamp>", clientTime);
string clientVersion = "<version>1</version>";
string termStoreIds = string.Format("<termStoreId>{0}</termStoreId>", termStoreId.ToString("D"));
string termSetIds = string.Format("<termSetId>{0}</termSetId>", termSetId.ToString("D"));
string serverTermSetTimestampXml;
string result = _wssTax.GetTermSets(termStoreIds, termSetIds, 1033, clientTimestamps, clientVersion, out serverTermSetTimestampXml);

So, there are a lot of parameters to that call – I’ll deal with them in part 3, which will be about caching. You’ll note that you can retrieve multiple termsets from multiple termstores – I think. I’ve not tried it (I’d rather make several calls and keep things simple).

Let’s look on what we get back from the service:

Nice. So much for XML being human readable. So what’s this about?

First off, notice that there’s no nesting. All Terms are returned in a flat list:

The elements of the terms are:

  • TS – Term Set
  • T – The Term.
  • LS – Label Set
  • TL – Term Label. Potentially a Term can have several labels, for different Languages
  • TMS – More Term Set Information
  • TM – Term Information
  • TD – Term Description

The attributes are all numbered, which is really helpful. What do they mean?

  • a9 – Term ID or TermSet ID
  • a11 – TermSet Description
  • a12 – Term Set Name the Term belongs to
  • a16 – Submission Policy (Is the termset open or closed)
  • a17 – Term is Enabled (can be used for tagging)
  • a21 – (boolean) False if the term is not deprecated
  • a24 – Term Set ID the Term belongs to
  • a25 – Parent Term ID
  • a31 – (boolean) Not sure, I think this is true if it’s the default term label?
  • a32 – Label Text
  • a40 – Parent Term Name
  • a45 – A semicolon separated list of the IDs of the Terms to the current term’s location in the taxonomy. (I.e. its path!)
  • a61 – (integer) ?
  • a67 – ?
  • a68 – TermSet contact email

Nice and simple, eh?

Still, using this information you can determine the structure of the termset. In Part 3, we’ll look at caching.

Working with the TaxonomyClientService: Part 2 – Get the TermSet (and understand it!)

3 thoughts on “Working with the TaxonomyClientService: Part 2 – Get the TermSet (and understand it!)

  1. KC says:

    Hi Andy, Thanks for your blog it was really informative.. i’m trying to create a web proxy by using your code for “Get Terms “, but I’m getting this error ~

    “The type or namespace name ‘Sharepoint_Taxonomy’ could not be found (are you missing a using directive or an assembly reference?);”

    I know I may be missing a reference but I have no clue what it is. I used the following already:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Net;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.Taxonomy;

    I’m a newbie in c# unfortunately… many thanks for your help!

    1. It sounds more like the issue is the web reference or service reference to the TaxonomyClientService web service. Have you checked those?

  2. Sergey says:

    Hi, Andy. In my case attribute “a40” has another meaning. This is term’s path (without its label) like attribute “a45”, but it’s a sequence of labels instead of a sequence of guids.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.