1

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.

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
user3556527
  • 51
  • 1
  • 5
  • I would guess, that most probably the permissions are problems - either account that runs the MVC application pool doesn't have enough permissions to load these instances, or you're having double-hop issue with credentials. – Marek Kembrowski May 08 '14 at 11:56
  • Thanks for replying. Perhaps you are correct about the permissions. But why it work with as a console application? Would you know how to set the credentials from the clientContext object? Or how would I go about changing the permissions? – user3556527 May 08 '14 at 16:26
  • Marek: In my MVC web application I did set the credentials explicitly but I still got the same error. I also made sure the user was a DBOwner to all workflow databases. COde still fails on this line in either MVC CSOM WorkflowInstanceCollection instances = instanceService.EnumerateInstancesForListItem(listId, itemId); or my JSOM code var instances = instanceService.EnumerateInstancesForListItem(listId, listItem); Do you have any suggesstions? – user3556527 May 08 '14 at 17:48
  • Can you update or add code with explicitly set permissions? Just for test, you can try changing the AppPool account to yours, or run the console up as AppPool account to check if this works. Also, if you have MVC app on different server, then you can still have double-hop issue. – Marek Kembrowski May 09 '14 at 08:25
  • Yes, I added coded to use explicit permissions. Console app works fine with or without explicit permissions. The MVC app does not! I converted my code to JSOM and still have same problem. Also, I place the MVC CSOM code in a try catch, yet the catch is not being called. Can you suggest anything else? – user3556527 May 09 '14 at 10:43
  • Hmm, sorry for late response, i didnt have time to check this issue. My another suggestion is to install fiddler/wireshark and try to see what packets are sent from your MVC app to SharePoint. I'm still guessing that this is double-hop issue. As for try-catch block, i would guess that your dlls weren't updated correctly. – Marek Kembrowski May 13 '14 at 06:31

2 Answers2

0

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.

0

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);
         }
      }
   }                   
 });
user3556527
  • 51
  • 1
  • 5