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?
[UPDATE]
Here's some sample code so you can see what I'm doing, lets start with the service implementation:
[BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
[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);
SetPQRContentType(newUrl);
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";
request.Update();
}
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