MikeJ82
MikeJ82

Reputation: 332

dotNetRdf Query to Sparql endpoint not working

I am struggeling to run Sparql queries from within my .NET 7 application.

First, I am configuring my HttpClient in Program.cs

services.AddHttpClient("sparql", httpClient =>
        {
            var url = context.Configuration.GetSection("Sparql").GetValue<string>("EndpointUrl");
            var header = context.Configuration.GetSection("Sparql").GetValue<string>("AuthorizationHeaderValue");

            httpClient.BaseAddress = new Uri("https://.../query");
            httpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, header);
        });

Then, I do the following to send a query:

string query = @"...";

var endpoint = new VDS.RDF.Query.SparqlQueryClient(_client, new Uri("https://.../query"));
SparqlConnector connector = new SparqlConnector(endpoint);

Object results = connector.Query(query);

I am getting what looks like a timeout exception after a longer period of waiting. (The query is limited to 10 results, this should not be the issue.)

I have also been looking here: https://dotnetrdf.org/docs/2.7.x/user_guide/Triple-Store-Integration.html#query

This would work but here, I am lacking the possibility to specify my Basic Authentication header.

Any hints on this would be greatly appreciated.

Update I am using dotNetRdf Version 3.0.0, which was released in spring of this year. The documentation does not seem to be up to date throughout.

Upvotes: 0

Views: 134

Answers (1)

MikeJ82
MikeJ82

Reputation: 332

I have found a working solution after some digging.

var endpoint = new VDS.RDF.Query.SparqlQueryClient(_myHttpClient, new Uri("https://.../query"));

var result = await endpoint.QueryWithResultSetAsync(myQuery);

Turns out that you don't need an instance of SparqlConnector to query the endpoint.

Upvotes: 0

Related Questions