SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a little function that updates a taxonomy field on a listitem. It does work when I call it from the SharePoint site, but If I call it from a WCF service (built on top of SharePoint's WCF factory) it does not updates the field (and it does not throws an exception or anything) Any ideas?


Here's some sample code so you can see what I'm doing, lets start with the service implementation:

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]    
    public class PQRSService : IPQRSService
        public void CancelPQRRequest(Guid libraryID, int pqrID)
            PQRSBLL.CancelPQRRequest(libraryID, pqrID);

Now, the Cancel pqr request:

public static void CancelPQRRequest(Guid libraryID, int pqrID)
            SPList library = SPContext.Current.Web.Lists.GetList(libraryID, false);
            SPListItem request = library.GetItemById(pqrID);
            SPFolder requestAsociatedFolder = request.Folder;

            SPContext.Current.Site.AllowUnsafeUpdates = true;
            SPContext.Current.Web.AllowUnsafeUpdates = true;

            MarkPQRAsCancelled(ref request);
            LogCancellation(ref requestAsociatedFolder);
            if (IsRequestInRecord(ref request))
                string recordID = RemoveRequestFromRecord(ref request);
                UpdateRecordInformation(recordID, request[CustomSiteColumns.FIELD_DOCSET_UNIQUE_ID].ToString());
            string newUrl = MovePQRToCancelledPQRLibrary(ref requestAsociatedFolder);

            SPContext.Current.Site.AllowUnsafeUpdates = false;
            SPContext.Current.Web.AllowUnsafeUpdates = false;

Now the MarkPQRAsCancelled, which is the place where the "magic happens"

private static void MarkPQRAsCancelled(ref SPListItem request)
            request[CustomSiteColumns.FIELD_DOCUMENT_STATUS] = TermStoreHelper.GetTaxonomyFieldByTerm(GlobalConstants.METADATA_GROUP_NAME, GlobalConstants.METADATA_TERM_STATUS, GlobalConstants.METADATA_TERM_STATUS_ANULADO);
            request[CustomSiteColumns.FIELD_CURRENT_ACTION] = "MoveTo";

Let's keep going on...

public static TaxonomyFieldValue GetTaxonomyFieldByTerm(string taxonomyGroupName, string taxonomyTermSet, string taxonomyTerm)

            var taxonomyTermS = GetTermSetByName(taxonomyGroupName, taxonomyTermSet);
            if (taxonomyTermS == null) throw new Exception("Termset:" + taxonomyTermSet + " does not exists");
            var term = taxonomyTermS.Terms.Where(c => string.Compare(c.Name, taxonomyTerm, true) == 0).FirstOrDefault();
            if (term == null) throw new Exception("Term:" + taxonomyTerm + " does not exist");
            TaxonomyFieldValue val = new TaxonomyFieldValue(string.Empty);
            val.PopulateFromLabelGuidPair(taxonomyTerm + "|" + term.Id);
            val.WssId = -1;

            return val;


And on...

public static TermSet GetTermSetByName(string taxonomyGroupName, string taxonomyTermSet)
            var taxonomyGroup = GetTaxonomyGroupByName(taxonomyGroupName);
            if (taxonomyGroup == null) throw new Exception("Taxonomy group:" + taxonomyGroupName + " does not exits");
            return taxonomyGroup.TermSets.Where(c => string.Compare(c.Name, taxonomyTermSet, true) == 0).FirstOrDefault();

And on...

public static Group GetTaxonomyGroupByName(string GroupName)
            var site = SPContext.Current.Site;
            var session = new TaxonomySession(site);
            return session.TermStores[ConfigurationHelper.GetInstance().ConfigItems[GlobalConstants.METADATA_SERVICE_NAME]].Groups.Where(c => string.Compare(c.Name, GroupName, true) == 0).FirstOrDefault();

Well that's pretty much everything, again, any help would be appreciated

share|improve this question
What version of SharePoint are you using? If it is 2010, then check the namespace you are using, it exists but it does nothing. This is 2013 functionality (It does work in 2013). – Hugh Wood Nov 15 '12 at 16:51
have you tried updating a field using PowerShell? – Falak Mahmood Nov 15 '12 at 19:26
@HughWood what do you mean it does nothing? (again it works like a charm when I'm calling the function from a webpart for example, but from a webservice does nothing) (yes I'm using SP2010) – Jaime Nov 19 '12 at 14:13
Have you debugged the code to see he actually gets to the taxonomy field value assignment in the WCF service ? Also, I always use a different way of setting the TaxonomyField: I've found it to be the most reliable way. – Cameron Verhelst Jul 7 '14 at 6:40


You are almost there, at first I thought you where referencing the 2013 namespace which does exist, it just doesn't work, now I know a bit more I am 90% sure you can get around your issue with the following. I know I know it might not seem to be what you want at first, but I assure you it is.

I see what you are doing now and I think this will work for you.

WssID = -1 = This term hasn't been used yet.

Setting Managed Metadata via CSOM This explains the situation in detail, the basics is the handler isn't there unless you are doing it locally. Remember all Managed-Metadata fields are, are extended lookup fields. This will explain pretty much everything you need to know. If you want to update MM fields remotely, this is the way to go.

Some further reading if the WssID isn't created

note: Microsoft.SharePoint.Taxonomy.WebServices.TaxonomyClientService Is only for SharePoint 2013.

share|improve this answer
I'm not updating the taxonomy field through the taxonomy field client api. I'm using var site = SPContext.Current.Site; var session = new TaxonomySession(site); return session.TermStores[ConfigurationHelper.GetInstance().ConfigItems[GlobalConstants‌​.METADATA_SERVICE_NAME]].Groups.Where(c => string.Compare(c.Name, GroupName, true) == 0).FirstOrDefault(); to get the group and then the taxonomy value which it does fetch. Then I assign the value to the field and call the item.Update(). Then if I check the field it still has the past value – Jaime Nov 19 '12 at 15:20
Well as an update someone has become a godsend. Please check out this blog, this is an example post, there is much more to read and learn here than I can abbreviate, and I am just going through it myself. However things that weren't possible before, are now (Same theory applies to all CSOM not just ECMA script).… – Hugh Wood Nov 19 '12 at 15:32
Oh and Jaime, could you post your code for people to have a look at, what you stated in your question and in this comment you just posted here seem to be missing something. A code example will deeply help. – Hugh Wood Nov 19 '12 at 15:34
Ok I'm gonna update the question and include some code :) – Jaime Nov 19 '12 at 15:42
As I thought... updating my question to be more clear, but I believe there is a work around. – Hugh Wood Nov 19 '12 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.