Microsoft.Workflow.Client.AuthenticationException “Authentication Failed”

When attempting to publish a workflow in SharePoint 2013 . you may facing following problem.

System.InvalidOperationException: Operation failed with error Microsoft.Workflow.Client.AuthenticationException: Authentication Failed. Valid credentials must be provided for one of the following protocols: Bearer, Negotiate. HTTP headers received from the server – ActivityId: 440bd264-3528-4880-91c9-03247a2e5e10. NodeId: WFSERVER01. Scope: /SharePoint/default/e72269ca-0e8c-4bd6-800a-9499da19f233. WWW-Authenticate: Bearer realm=”22a5da47-566b-4e0b-90f9-76752903b68e”, client_id=”00000005-0000-000

TroubleShooting Steps
1) First you have to check installation and upgrades:
It is important that any Cumulative Updates (CU) for SharePoint Server 2013 and Workflow Manager are installed in a coordinated fashion. After an update has been performed, several Windows PowerShell cmdlets must be run in order to maintain the connection between the SharePoint Server 2013 farm and the Workflow Manager farm.
Check that you have Service Bus 1.1
Check that you have Workflow Manager 1.0 Refresh installed
Check that you have Workflow Manager 1.0 Refresh Client (must installed all SharePoint Servers)
Check that you have at least SharePoint 2013 SP1.
(Article Date: 24/12/2014)

If you want to use Workflows with Microsoft supportability you need to have latest bits is running.

2) Check Network connections. (Dont miss this step is very important , Even Some Scenarios it looks working while you can save workflows and Worflow Manager Service looks connected but this issue can happen)
SharePoint Servers (WFEs) must able to reach Workflow Manager web site
And also it is a requirement that from Worflow Manager Machine (if it is a different machine) must able to browse the site url which you use to register-spworkflowservice.
Ping both machines that have ip communication
And also Check Proxies

3) Check all host file entries on every server that is there something preventing network communication .

4) Check Firewall rules and communications.

5) Test your credentials are correct or not .

7) Check Workflow Services are running , Workflow Manager Web Site is up and Application pool is alive.

8) If workflow manager is hosted on a different machine check IIS configuration that you have Windows Authentication is enabled.

9) Try re-register workflow service by scopename;
Register-SPWorkflowService -SPSite ‘http://mywebsite’ -WorkflowHostUri ‘https://workflowhost’ -AllowOAuthHttp -scopename “SharePoint”  -Force

10) If it doesnt work ; unregister the Workflow manager from the sharepoint farm
Get-SPWorkflowServiceApplicationProxy | Remove-SPServiceApplicationProxy
and run
Register-SPWorkflowService -SPSite ‘http://mywebsite’ -WorkflowHostUri ‘https://workflowhost’ -AllowOAuthHttp -scopename “SharePoint”  -Force
this will recreate the SPWorkflowServiceApplication Proxy.

(Dont Forget make an iisreset after use “Register-SPWorkflowService”)

11) Verify you have using latest activities are updated through the Workflow Manager.

$credential = [System.Net.CredentialCache]::DefaultNetworkCredentials
$site = Get-SPSite(<siteUri>)
$proxy = Get-SPWorkflowServiceApplicationProxy
$svcAddress = $proxy.GetWorkflowServiceAddress($site)
Copy-SPActivitiesToWorkflowService -WorkflowServiceAddress $svcAddress -Credential $credential -Force $true

Make your test with creating a new workflow and publish.





Avoid using SPFolder.Item cause performance issue on large lists

When you call an “SPFolder.Item” Property ; it  executes below code once on Its parent Folder (if Parent Folder is not empty). this is a kind of Caching & Indexing mechanizm .Then returning related item from index of parent folder.

m_FileRefDict = new Hashtable(
StringComparer.Create(CultureInfo.InvariantCulture, true /*ignoreCase*/));

foreach (SPListItem item in items) *** Thats where we creating the long SQL query.
m_FileRefDict[item[SPGlobal.FieldNames.strFileRef].ToString()] = item;

And the code has to be like that . For Large lists ; in the Sitiuation has getting worse and it brings all items and makes sense of slow query for large lists specially over threshold paths.

SharePoint Supports 30,000,000 Item per list But max item count should not be exceed 5000 in a folder including root folder of the list. DocumentSets are also considered as Folder.

In that condition our suggestions , Don’t use “SPFolder.Item” property ! which is creating performance degradation.

Instead of that :

Use “SPQuery” if you want to get the item of a SPFolder (or DocumentSet)

 For Querying a DocumentSet item you can use following query;
SPList list = Site.RootWeb.Lists["Documents"];
// Or
// SPList = Site.RootWeb.GetList(“<List URL>”)

var query = new SPQuery();
query.RowLimit = 1;
//query.Folder = Library; //if it is present in a Folder.
query.ViewFields = "<FieldRef Name='ID' /><FieldRef Name='Title' />";//Limit the returning field count for gain performance.
query.ViewFieldsOnly = true;
 query.Query = string.Format(“<Where><And><Eq><FieldRef Name=’ContentType’ /><Value Type=’Computed’>Document Set</Value></Eq><Eq><FieldRef Name=’Title’ /><Value Type=’Text’>{0}</Value></Eq></And></Where>”, documentSetName);

var itemcollection = list.GetItems(query);

foreach(SPListItem item in itemcollection)
Console.WriteLine(item.ID + " " + item.Title);