locked
Data Service Error accessing SharePoint list RRS feed

  • Question

  • I am trying to access some SharePoint lists from a .Net (C#) web application. I googled the topic and it seemed the consensus was to use WCF Data Service (steps outlined below, in case I missed something). After I get the data, I display it in a jQuery datatable, using Ajax web service call to grab the data. The data returned by web service is jsonified and passed to data table.

    First step was to run DataSvcUtil.exe to create a DataService.cs file that contains the client data service classes that are needed to access a data service from a .NET Framework client application. Then added references to Microsoft.Data.OData.dll and Microsoft.Data.Services.Client.dll. I created a we service API:

    [WebMethod] [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)] public string GetCompletedAssessments() { SPService_DataContext dc = new SPService_DataContext(new Uri("http://my_sp_site_.com/sites/nvx/SPService/_vti_bin/listdata.svc/")); dc.Credentials = System.Net.CredentialCache.DefaultCredentials; var source = dc.CompletedAssessments; // I had to use the following, otherwise only 1,000 records would be returned; I had 16,000 records; var newSource = Utils.SelectAll(dc, dc.CompletedAssessments);

    // this is also line 66 referred to in error trace

        string JSONresult = JsonConvert.SerializeObject(newSource);
        return JSONresult;
    }
    
    public static List<T> SelectAll<T>(this SPService_DataContext dataContext, IQueryable<T> query)
    {
        var list = new List<T>();
    
        System.Data.Services.Client.DataServiceQueryContinuation<T> token = null;
        // this is also line 625 referred to in error trace
        var response = ((System.Data.Services.Client.DataServiceQuery)query).Execute() as System.Data.Services.Client.QueryOperationResponse<T>;
    
        do
        {
            if (token != null)
            {
                response = dataContext.Execute(token);
            }
            list.AddRange(response);
        } while ((token = response.GetContinuation()) != null);
    
        return list;
    }

    My Issues:

    When run locally, from within VS 2017, or from IIS Manager on application server, I get all the data, albeit in 80 seconds (way too long for 16,000 records). However when I deploy and run this from a browser, I get status code 500 error and can't see why.

    Secondly, when I look at the error trace I see references to some files containing my development path. This is what I see:

    error - 
    Internal Server Error... 
    Status: 500, 
    ResponseText: 
    {
    "Message":"An error occurred while processing this request.",
    "StackTrace":" 
    at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
    at System.Data.Services.Client.DataServiceQuery`1.Execute() 
    at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator() 
    at System.Data.Services.Client.DataServiceQuery`1.System.Collections.IEnumerable.GetEnumerator() 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
    at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
    at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
    at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)
    at EA.easg.GetCompletedAssessments() in D:\\Source Codes\\EATest\\EA\\EA\\Services\\easg.asmx.cs:line 66",
    
    "ExceptionType":"System.Data.Services.Client.DataServiceQueryException"
    }
    I have googled the heck of this and can't seem to get anywhere. I really need some help here.
    Tuesday, February 6, 2018 7:53 PM

All replies

  • Hi BiKhoda,

    Please try the following trouble shooting.

    Issue: Website cannot display the page due to HTTP 500 Internal Server Error. Tried to open SharePoint Central Administration to see if the same error message appears. Was able to open Central Administration without any errors.

    Opened IIS Manager to make sure SharePoint – 80 Application Pool was running and noticed that SecurityTokenServiceApplicationPool application pool was stopped.

    Started SecurityTokenServiceApplicationPool application pool, refreshed the SharePoint site but that did not resolve the issue. Opened IIS manager and noticed.that SecurityTokenServiceApplicationPool was stopped again.

    Checked the IIS events log to see what’s the issue with SecurityTokenServiceApplicationPool application pool.

    https://social.technet.microsoft.com/wiki/contents/articles/25591.sharepoint-2013-troubleshooting-http-500-internal-server-error.aspx

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 28, 2018 8:37 AM
    Moderator