Not applicable

Terminate Workflow by Code

The following Code was made for terminating the REQUEST
which works fine on the Development Server and error on Production Server

 

   
var

wcfWindowUserName = ConfigurationManager.AppSettings["WCFWindowUserName"];

          
var wcfWindowPassword = ConfigurationManager.AppSettings["WCFWindowPassword"];

          
var wcfDomain = ConfigurationManager.AppSettings["WCFDomain"];

         

            try

          
{

 

 

              
var webServiceUrl = web.Url;

              
//construct web service url

              
if (!webServiceUrl.EndsWith("/"))

                  
webServiceUrl += "/";

              
webServiceUrl += "_vti_bin/nintexworkflow/workflow.asmx";

          

                //Call the Nintex web service to publish/save the workflow

              
var service = new
WorkflowWS.NintexWorkflowWS

              
{

                  
Timeout = 999999999,

                  
Url = webServiceUrl,

                  
// Credentials = new NetworkCredential(wcfWindowUserName,
wcfWindowPassword, wcfDomain)

   
              

                };

 

              
var lst = web.Lists[listName];

              
var lstId = lst.ID;

              
//var itemGUID = new
Guid(Request.QueryString["rfID"]);

              
var itemId = GetItemIDByTitle(lst,
itemGUID.ToString());

              
var wfInstanceId =
GetWorkflowInstanceIdWithUpdateStatus(itemGUID, type);

 

              
if (itemId != 0)

              
{

                  
service.Credentials = new NetworkCredential(wcfWindowUserName,
wcfWindowPassword, wcfDomain);

                  
service.UnsafeAuthenticatedConnectionSharing = true;

                  
service.PreAuthenticate = true;

                  
//service.Credentials = CredentialCache.DefaultCredentials;

                  
service.TerminateWorkflow(lstId, itemId, wfInstanceId);

                  
//DeleteListItem(lst, itemId);

 

              
}

 

This is the Following Message I am receiving

 

The request failed
with HTTP status 401: Unauthorized.System.Web.Services

0 Kudos
Reply
7 Replies
Not applicable

Re: Terminate Workflow by Code

Hi Shoeb AbdulMoiz​,

Seems that the account that is trying to execute the web service does not have the correct permissions on SharePoint (it should have Manage list or up permission level to cancel a workflow). Could you verify this.

0 Kudos
Reply
Not applicable

Re: Terminate Workflow by Code

Ramses Kooijman

Hello Mr. Ramses,

Thanks for your Reply, the Account i am using is Admin Account. Here is more detail for the Error

lblErorr.Text = ex.Message + "," + ex.StackTrace + "," + "," + ex.TargetSite + "," + ex.Source + "," + ex.InnerException + "," + ConfigurationManager.AppSettings["WCFWindowUserName"];

The request failed with HTTP status 401: Unauthorized.System.Web.Services, at

SSPWorkflow.Classess.NintexClass.Terminate.TerminateWorkflow(SPWeb web, Guid

itemGUID, WorkflowType type, Boolean withNewRequest) at

SSPWorkflow.WebParts.TerminateRequests.TerminateRequestsUserControl.btnRequest_Click(Object

sender, EventArgs e),,Void TerminateWorkflow(Microsoft.SharePoint.SPWeb,

System.Guid, SSPWorkflow.Classess.NintexClass.WorkflowType, Boolean),SSPWorkflow

regards,

0 Kudos
Reply
Not applicable

Re: Terminate Workflow by Code

Hi Shoeb AbdulMoiz​,

Try running it in elevated mode like:

    SPSecurity.RunWithElevatedPrivileges(delegate()

    {

            <code>

    });

0 Kudos
Reply
Not applicable

Re: Terminate Workflow by Code

Capture.JPG

Hi Ramses Kooijman

The Following occurred after running the Above Code.

0 Kudos
Reply
Not applicable

Re: Terminate Workflow by Code

Hi Shoeb AbdulMoiz​,

I must admit that my coding skills are not so great so i guess am at a loss here as well

0 Kudos
Reply
waltont
Scholar

Re: Terminate Workflow by Code

The user account "SPPWorkflow" you're using in dev may not have production level access to the same things. You should check to make sure it has the same access on your production server.

A 401 unauthorized means exactly that. Either the password is wrong (which i doubt since it works in dev, though its possible on the prod server the password is different for security reasons) or the user account does not have appropriate security level access to the functions you're calling - in this case the terminateWorkflow() function. There's nothing else that would cause it code-wise if the same exact code is in development as it is in production. Clearly it works in development so there's no reason it would fail in production if the account you're using has access.

0 Kudos
Reply
waltont
Scholar

Re: Terminate Workflow by Code

here's another thing you might try:

Try to visit the URL in a normal web browser session: http://<yourProdSharepointHere>/<yourSubsiteURLHere>/_vti_bin/nintexworkflow/workflow.asmx?op=TerminateWorkflow

If you can get there without receiving a 401 error, change the credentials in the app.settings to your windows login account info. If you are able to then run the workflow fine then you'll need to get the SPPWorkflow account access rights to the nintex web services. If you can't hit that site, log into your computer using the SPPWorkflow account and try it again. If you can't get there with either, then neither account has the access to the nintex web services and you'll need to either obtain those rights on your production account or your personal account or whatever. Probably best to give the rights to the service account you're using. You can also try /_vti_bin/nintexworkflow/workflow.asmx?WSDL for the Web Service Definition Language response as well. It should respond with an XML output of the entire nintexworkflow web service and all functions built in.

You can also try this on your development environment to see what it should look like since you know it works there.

Let me know how that goes.

0 Kudos
Reply