Class SparqlQueryClient
A class for connecting to a remote SPARQL endpoint and making queries against it using the System.Net.Http library.
Inherited Members
Namespace: VDS.RDF.Query
Assembly: dotNetRdf.dll
Syntax
public class SparqlQueryClient : ISparqlQueryClient, IConfigurationSerializable
Constructors
| Edit this page View SourceSparqlQueryClient(HttpClient, Uri)
Create a new SPARQL client.
Declaration
public SparqlQueryClient(HttpClient httpClient, Uri endpointUri)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpClient | httpClient | The underlying client to use for HTTP requests. |
| Uri | endpointUri | The URI of the SPARQL endpoint to connect to. |
Properties
| Edit this page View SourceDefaultGraphs
Gets the Default Graph URIs for Queries made to the SPARQL Endpoint.
Declaration
public List<string> DefaultGraphs { get; }
Property Value
| Type | Description |
|---|---|
| List<string> |
EndpointUri
Gets the URI of the remote SPARQL endpoint.
Declaration
public Uri EndpointUri { get; }
Property Value
| Type | Description |
|---|---|
| Uri |
HttpMode
Get or set the mode used to determine the HTTP method to be used by the client.
Declaration
public HttpMode HttpMode { get; set; }
Property Value
| Type | Description |
|---|---|
| HttpMode |
Remarks
The default mode is Auto which uses a GET unless the SPARQL query is too long or contains characters that cannot be encoded as an HTTP query string, in which case POST is used.
NamedGraphs
Gets the List of Named Graphs used in requests.
Declaration
public List<string> NamedGraphs { get; }
Property Value
| Type | Description |
|---|---|
| List<string> |
RdfAcceptHeader
Gets/Sets the Accept Header sent with CONSTRUCT/DESCRIBE queries.
Declaration
public string RdfAcceptHeader { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Can be used to workaround buggy endpoints which don't like the broad Accept Header that dotNetRDF sends by default. If not set or explicitly set to null the library uses the default header generated by HttpAcceptHeader.
ResultsAcceptHeader
Gets/Sets the Accept Header sent with ASK/SELECT queries.
Declaration
public string ResultsAcceptHeader { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Can be used to workaround buggy endpoints which don't like the broad Accept Header that dotNetRDF sends by default. If not set or explicitly set to null the library uses the default header generated by HttpSparqlAcceptHeader.
Methods
| Edit this page View SourceQueryAsync(string, IRdfHandler, ISparqlResultsHandler, CancellationToken)
Execute a SPARQL query.
Declaration
public Task QueryAsync(string sparqlQuery, IRdfHandler graphHandler, ISparqlResultsHandler resultsHandler, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| IRdfHandler | graphHandler | The handler to use when paring graph results from a CONSTRUCT or DESCRIBE query. |
| ISparqlResultsHandler | resultsHandler | The handler to sue when parsing SPARQL results sets from a SELECT or ASK query. |
| CancellationToken | cancellationToken | A cancellation token that can be used by other objects or threads to receive notice of cancellation. |
Returns
| Type | Description |
|---|---|
| Task |
QueryInternal(string, string, CancellationToken)
Internal method which builds and executes the query as a GET or POST as appropriate.
Declaration
protected Task<HttpResponseMessage> QueryInternal(string sparqlQuery, string acceptHeader, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The SPARQL query string. |
| string | acceptHeader | The value to insert into the Accept header of the outgoing HTTP request. |
| CancellationToken | cancellationToken | A cancellation token that can be used by other objects or threads to receive notice of cancellation. |
Returns
| Type | Description |
|---|---|
| Task<HttpResponseMessage> |
QueryWithResultGraphAsync(string)
Execute a SPARQL query that is intended to return an RDF Graph.
Declaration
public Task<IGraph> QueryWithResultGraphAsync(string sparqlQuery)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
Returns
| Type | Description |
|---|---|
| Task<IGraph> | An RDF Graph. |
Remarks
This method should be used when processing SPARQL CONSTRUCT or DESCRIBE queries.
QueryWithResultGraphAsync(string, CancellationToken)
Execute a SPARQL query that is intended to return an RDF Graph.
Declaration
public Task<IGraph> QueryWithResultGraphAsync(string sparqlQuery, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| CancellationToken | cancellationToken | A cancellation token that can be used by other objects or threads to receive notice of cancellation. |
Returns
| Type | Description |
|---|---|
| Task<IGraph> | An RDF Graph. |
Remarks
This method should be used when processing SPARQL CONSTRUCT or DESCRIBE queries.
QueryWithResultGraphAsync(string, IRdfHandler)
Execute a SPARQL query that is intended to return an RDF Graph.
Declaration
public Task QueryWithResultGraphAsync(string sparqlQuery, IRdfHandler handler)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| IRdfHandler | handler | The handler to use when parsing the graph data returned by the server. |
Returns
| Type | Description |
|---|---|
| Task | An RDF Graph. |
Remarks
This method should be used when processing SPARQL CONSTRUCT or DESCRIBE queries.
QueryWithResultGraphAsync(string, IRdfHandler, CancellationToken)
Execute a SPARQL query that is intended to return an RDF Graph.
Declaration
public Task QueryWithResultGraphAsync(string sparqlQuery, IRdfHandler handler, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| IRdfHandler | handler | The handler to use when parsing the graph data returned by the server. |
| CancellationToken | cancellationToken | A cancellation token that can be used by other objects or threads to receive notice of cancellation. |
Returns
| Type | Description |
|---|---|
| Task | An RDF Graph. |
Remarks
This method should be used when processing SPARQL CONSTRUCT or DESCRIBE queries.
QueryWithResultSetAsync(string)
Execute a SPARQL query that is intended to return a SPARQL results set.
Declaration
public Task<SparqlResultSet> QueryWithResultSetAsync(string sparqlQuery)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
Returns
| Type | Description |
|---|---|
| Task<SparqlResultSet> | The query results. |
Remarks
This method should be used when processing SPARQL SELECT or ASK queries.
QueryWithResultSetAsync(string, CancellationToken)
Execute a SPARQL query that is intended to return a SPARQL results set.
Declaration
public Task<SparqlResultSet> QueryWithResultSetAsync(string sparqlQuery, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| CancellationToken | cancellationToken | A cancellation token that can be used by other objects or threads to receive notice of cancellation. |
Returns
| Type | Description |
|---|---|
| Task<SparqlResultSet> | The query results. |
Remarks
This method should be used when processing SPARQL SELECT or ASK queries.
QueryWithResultSetAsync(string, ISparqlResultsHandler)
Execute a SPARQL query that is intended to return a SPARQL results set.
Declaration
public Task QueryWithResultSetAsync(string sparqlQuery, ISparqlResultsHandler resultsHandler)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| ISparqlResultsHandler | resultsHandler | The handler to use when parsing the results returned by the server. |
Returns
| Type | Description |
|---|---|
| Task | The query results. |
Remarks
This method should be used when processing SPARQL SELECT or ASK queries.
QueryWithResultSetAsync(string, ISparqlResultsHandler, CancellationToken)
Execute a SPARQL query that is intended to return a SPARQL results set.
Declaration
public Task QueryWithResultSetAsync(string sparqlQuery, ISparqlResultsHandler resultsHandler, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sparqlQuery | The query to be executed. |
| ISparqlResultsHandler | resultsHandler | The handler to use when parsing the results returned by the server. |
| CancellationToken | cancellationToken | A cancellation token that can be used by other objects or threads to receive notice of cancellation. |
Returns
| Type | Description |
|---|---|
| Task | The query results. |
Remarks
This method should be used when processing SPARQL SELECT or ASK queries.
SerializeConfiguration(ConfigurationSerializationContext)
Serializes the Endpoint's Configuration.
Declaration
public void SerializeConfiguration(ConfigurationSerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| ConfigurationSerializationContext | context | Configuration Serialization Context. |