简体   繁体   中英

ExecutionEngineException for canceling my SharePoint 2013 Workflow

I am using SharePoint 2013, VS2013 and Workflow engine 4.5. I have a custom Application page that I use for the next step in my workflow process. One the buttons on this page is a cancel button. When my users click this, I use ajax to call into my MVC web application. My MVC5.0 application I first update my Entity Framework database record then try to cancel the workflow.

Below is my MVC code. Why am I getting ExecutionEngineException error at this line clientContext.Load(instances); Note: If the take the below code and copy it to a console application it works!

            //cancel the workflow
            ClientContext clientContext = new ClientContext(baseUrl);
            WorkflowServicesManager wfsm = new WorkflowServicesManager(clientContext, clientContext.Web);
            WorkflowInstanceService instanceService = wfsm.GetWorkflowInstanceService();
            WorkflowInstanceCollection instances = instanceService.EnumerateInstancesForListItem(listId, itemId);
            **clientContext.Load(instances);**
            clientContext.ExecuteQuery();

            foreach (WorkflowInstance instance in instances)
            {
                if (instance.Id == new Guid(instanceId))
                {
                    instanceService.CancelWorkflow(instance);
                }
            }

Any help would be appreciated.

Marek:

I have opened a case with Microsoft (MS). Initial response they gave is that their are know security and other issues with SharePoint and MVC5. I tried using a SharePoint WCF Service project ad got same result. I'll let you know what i find out when MS responds. As for Fiddler, I tried that but it didn't tell me much or maybe I was not interpreting the results correctly. I really thought if I provided explicit credentials (same as the console app that works) but got same error.

I found out the CSOM code (above) needed to be replaced with the following code. Note: I also had to run the following code with elevated privledges.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
   using (SPSite site = new SPSite(baseUrl))
   {
      using (SPWeb web = site.OpenWeb())
      {
         SPList list = web.Lists["Documents"];
         Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager wsm = new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager(web);
         Microsoft.SharePoint.WorkflowServices.WorkflowInstanceService service = wsm.GetWorkflowInstanceService();
         var instances = service.EnumerateInstancesForListItem(gPageList, pageID);
         foreach (var instance in instances)
         {
            service.CancelWorkflow(instance);
         }
      }
   }                   
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM