Search code examples
c#semantic-webdbpediadotnetrdf

dotNetRDF Http Error when querying DBPedia


I am new to dotNetRDF and SPARQL and I'm trying to retrieve some person data from DBPedia. I have wrote this query and tested it successfully on the online editor at http://dbpedia.org/sparql :

The problem is that when I try to launch the query using the code below, I get an HTTP Exception 400, Invalid Request:

SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"));

        //Make a SELECT query against the Endpoint
        SparqlResultSet results = endpoint.QueryWithResultSet(@" 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n
PREFIX type: <http://dbpedia.org/class/yago/>\n
PREFIX prop: <http://dbpedia.org/ontology/>\n
\n
select DISTINCT ?person ?name ?birth ?shortDescription where {\n
?person a dbpedia-owl:Person ;\n
      foaf:name ?name ;\n
      dbpedia-owl:birthDate ?birth ;\n
      dbpprop:shortDescription ?shortDescription .\n
filter langMatches(lang(?name),'en') .\n
filter langMatches(lang(?shortDescription),'en') \n
}\n
LIMIT 10");
        foreach (SparqlResult result in results)
        {
            Console.WriteLine(result.ToString());
        }

Any help would be appreciated. Thanks in advance ;)


Solution

  • For the XML version error you can instruct dotNetRDF to request results in a non-XML format e.g.

    endpoint.ResultsAcceptHeader = "application/sparql-results+json";
    

    Would ask for JSON instead of XML which will avoid the XML version issue.

    As the documentation for that property says:

    Can be used to workaround buggy endpoints which don't like the broad Accept Header that dotNetRDF sends by default