Sharepoint

Data Service Exception "Unauthorised" when connecting to Sharepoint OData

If you are struggling to fetch data from a Sharepoint OData service and getting an error as below: [DataServiceClientException: Unauthorized] System.Data.Services.Client.QueryResult.Execute() +436914 System.Data.Services.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +133  Then ensure you are setting the Credentials property of your Data Service Context, as below: // Create the data context. SharepointDataContext dc = new SharepointDataContext(new Uri("http://dksp/_vti_bin/listdata.svc")); // Provide default credentials, without this authorisation will fail! dc.Credentials = System.Net.CredentialCache.DefaultCredentials; // Etc… var accounts = from a in dc.
Read more

The "Name attribute is invalid" when adding a Service Reference to a Sharepoint OData Service

Well this little issue took me a while to investigate, but the skinny is this: If you are going to add a service reference to a Sharepoint OData service (e.g. http://sharepoint/_vti_bin/listdata.svc) then make sure your Sharepoint site name does NOT begin with a number - otherwise Visual Studio will fail to add the reference. Quick and easy, but this took quite a while for me to find, hope it helps anyone in the same situation!
Read more