Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to kick off the user profile syc using a web service. Here is what i've tried :

[WebMethod]
        public string runUserProfileService()
        {
            var message = "";

            using (SPSite site = new SPSite("http://servernamehere/"))
            {
                site.AllowUnsafeUpdates = true;
                SPServiceContext context = SPServiceContext.GetContext(site);
                UserProfileConfigManager upcm = new UserProfileConfigManager(context);

                if (!upcm.IsSynchronizationRunning())
                {
                    try
                    {
                        upcm.StartSynchronization();
                        message = "running";
                        return message;
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                        return message;
                    }
                }

                message = "running";
            }

            return message;
        }

Here is the exception that I continue to get:

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

Any help would be appreciated.

thanks,

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Try adding

Context.Items["FormDigestValidated"] = true;
SPUtility.ValidateFormDigest();

to the beginning of your method.

Edit:

Revised code above.

share|improve this answer
    
I added this to the top of the method. When it hits this line I get the same error as before. –  ironman99 Feb 8 '13 at 20:17
    
How are you calling the webservice? Is it through a http get? –  Steve Lineberry Feb 9 '13 at 1:10
    
Ok, I changed the code in my answer. Try adding that at the top. –  Steve Lineberry Feb 9 '13 at 1:13
add comment

Your Answer

 
discard

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.