The following Code was made for terminating the REQUEST
which works fine on the Development Server and error on Production Server
wcfWindowUserName = ConfigurationManager.AppSettings["WCFWindowUserName"];
var wcfWindowPassword = ConfigurationManager.AppSettings["WCFWindowPassword"];
var wcfDomain = ConfigurationManager.AppSettings["WCFDomain"];
var webServiceUrl = web.Url;
//construct web service url
webServiceUrl += "/";
webServiceUrl += "_vti_bin/nintexworkflow/workflow.asmx";
//Call the Nintex web service to publish/save the workflow
var service = new
Timeout = 999999999,
Url = webServiceUrl,
// Credentials = new NetworkCredential(wcfWindowUserName,
var lst = web.Lists[listName];
var lstId = lst.ID;
//var itemGUID = new
var itemId = GetItemIDByTitle(lst,
var wfInstanceId =
if (itemId != 0)
service.Credentials = new NetworkCredential(wcfWindowUserName,
service.UnsafeAuthenticatedConnectionSharing = true;
service.PreAuthenticate = true;
//service.Credentials = CredentialCache.DefaultCredentials;
service.TerminateWorkflow(lstId, itemId, wfInstanceId);
This is the Following Message I am receiving
The request failed
with HTTP status 401: Unauthorized.System.Web.Services
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.
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
sender, EventArgs e),,Void TerminateWorkflow(Microsoft.SharePoint.SPWeb,
System.Guid, SSPWorkflow.Classess.NintexClass.WorkflowType, Boolean),SSPWorkflow
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.
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.