We just wanted to provide all tasks to qlikview but there is a small problem with authentication.
We are using CSOM to fetch all tasks from PWA.
It fetches all tasks properly when debugging but when it returns result is asking for credential on browser and gives 401 on qlikview.
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Tasks : ITasks
{
private readonly SPWeb currentWeb = SPContext.Current.Web;
private readonly UserCredentials credential = GetCredential("FarmCredential", CredentialType.Domain);
public List<TaskModel> Get()
{
var result = new List<TaskModel>();
try
{
var userName = string.Format("{0}\\{1}", credential.DomainName, credential.UserName);
using (var context = new ProjectContext(currentWeb.Url))
{
var projects = context.Projects;
context.Credentials = new NetworkCredential(userName, credential.Password);
context.RequestTimeout = int.MaxValue;
context.Load(projects);
context.ExecuteQuery();
projects.Take(2).Cast<PublishedProject>().ToList().ForEach((project) =>
{
var tasks = project.Tasks;
context.Load(tasks, task => task.IncludeWithDefaultProperties(p => p.Id,
p => p.Name,
p => p.Created,
p => p.TaskType,
p => p.Cost,
p => p.Deadline,
p => p.Start,
p => p.Finish,
p => p.IsActive,
p => p.Duration,
p => p.ActualStart,
p => p.ActualFinish,
p => p.ScheduledStart,
p => p.ScheduledFinish,
p => p.ScheduledDuration));
context.ExecuteQuery();
var customTasks = tasks.Select(task => new TaskModel
{
Id = task.Id,
Name = task.Name,
Created = task.Created,
TaskType = task.TaskType,
Cost = task.Cost,
Deadline = task.Deadline,
Start = task.Start,
Finish = task.Finish,
IsActive = task.IsActive,
Duration = task.Duration,
ActualStart = task.ActualStart,
ActualFinish = task.ActualFinish,
ScheduledStart = task.ScheduledStart,
ScheduledFinish = task.ScheduledFinish,
ScheduledDuration = task.ScheduledDuration,
ProjectId = project.Id
});
result.AddRange(customTasks);
});
}
}
catch (Exception ex)
{
DiagnosticLog.Error("[Foundation.Project.API.ISAPI] - Tasks - Get", ex);
}
return result;
}
}