none
Probelm connecting to the OData service RRS feed

  • Question

  • Hello everyone!

    I am currently exploring the reporting options that are offered by the Project Online OData service, but I am having trouble querying OData feeds (I am trying to do so from a C# application). I have been trying to use and adapt the code found here: https://msdn.microsoft.com/en-us/library/office/jj163048.aspx, in the "Creating LINQ queries" section. The first problem that I encountered was that I was unable to add the Service Reference. The URL was correct (tested and working in Google Chrome) but I was getting an HTML 403 error (Forbidden). I ended up downloading the edmx from the browser and creating the .cs file with datasvcutil.exe, which worked.

    I then went on to try and get some data from the server using the following code (basically a copy-paste from the page mentionned earlier) :

    using System.Text;
    using System.Net;
    using System.Data.Services.Client;
    using System.Security;
    
    namespace newOdataApp
    {
        class Program
        {
            private const string PSDATA = "https://lankatest.sharepoint.com/sites/pwa/_api/ProjectData";
    
            static void Main(string[] args)
            {
                ProjectOData.ReportingData context = new ProjectOData.ReportingData(new Uri(PSDATA, UriKind.Absolute));
                context.Credentials = CredentialCache.DefaultCredentials;
    
                var projectQuery1 = from p in context.Projects select p;
    
                try
                {
                    foreach (ProjectOData.Project proj in projectQuery1)
                    {
                        Console.WriteLine(proj.ProjectName);
                    }
                }
                catch(DataServiceQueryException e)
                {
                    Console.WriteLine(e.Response.Error.Message);
                }
    
                Console.ReadKey();
            }
        }
    }

    When I run this code, I get a DataServiceQueryException on the first foreach pass, the e.Response.Error.Message being "Response version '3.0' is not supported. The only supported versions are: '1.0', '2.0'." and the e.Response.StatusCode being 403. I then checked the DefaultCredentials only to realize that they were empty. Seeing that, I tried to change 

    context.Credentials = CredentialCache.DefaultCredentials;

    for 

    CredentialCache cc = new CredentialCache();
    cc.Add(new Uri(PSDATA, UriKind.Absolute), "Kerberos", new NetworkCredential("admin@lankatest.onmicrosoft.com", password));
    context.Credentials = cc;

    I also tried to move "lankatest.onmicrosoft.com" from the username to the NetworkCredential constructor's third argument like so:

    CredentialCache cc = new CredentialCache();
    cc.Add(new Uri(PSDATA, UriKind.Absolute), "Kerberos", new NetworkCredential("login", password, "lankatest.onmicrosoft.com"));
    context.Credentials = cc;

    I also tried both these methods with what I believe is the complete list of authentication schemes (Basic, Digest, Negotiate, NTLM, Kerberos) since I couldn't find which one I was supposed to use.

    Every single combination gave me the same result as the DefaultCredentials. I also tried adding credentials in both the "Windows Credentials" and "Generic Credentials" sections of Control Panel>All Control Panel Items>Credential Manager, hoping that DefaultCredentials would use this, but to no success.

    If anyone could point me to another method or at least some documentation, it would be deeply appreciated, since all my research has been unsuccesful.

    Great day to you,

    Étienne Lévesque



    Wednesday, August 3, 2016 3:16 PM

Answers

All replies

  • Hello,

    See a PowerShell example below:

    https://pwmather.wordpress.com/2016/05/17/extract-projectonline-or-projectserver-2013-2016-timesheet-data-powershell-office365/

    That should help you get started / see how to authenticate.

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Thursday, August 4, 2016 7:52 AM
    Moderator
  • Hello Paul,

    Thank you very much for your reply!

    With a little work I was able to adapt your script for C# and I was then able to get data from my Project Online tenant, but this technique leaves me unable to use the ProjectOData class generated from the edmx file, which kind of annoys me. I feel like my main problem lies in the error message "Response version '3.0' is not supported. The only supported versions are: '1.0', '2.0'.", as I was able to connect to Project Online with the WebRequest that I adapted from your script. I also changed my code to use a SharePointOnlineCredentials object instead of a CredentialCache one, but I kept getting the exact same result.

    Now, I did some digging and found the following value in e.Response.Headers: {[DATASERVICEVERSION, 3.0]}. I am guessing that this is most likely the "version" mentionned in the error message, but I haven't found a way to change it, as the HTML request is, I think, generated by the LINQ query.

    I have marked your reply as an answer, but I would really appreciate it if you (or anyone) could help further investigate this, as even though I have a working solution, I hate to leave a problem unanswered.

    Thank you very much,

    Étienne

    Thursday, August 4, 2016 4:19 PM