在dotNetRdf中为远程SPARQL连接器应用自定义请求选项

时间:2017-05-14 03:08:55

标签: c# .net sparql dotnetrdf

我正在尝试向HTTP重新设置SPARQL endpoint connector问题添加自定义标头。连接器can use是自定义remote endpoint,它继承了我可以覆盖的ApplyCustomRequestOptions方法。该方法的文档说

  

[...]为请求添加任何其他自定义请求选项/标头。

但是我的覆盖方法永远不会被调用(因此我的自定义选项未应用,因此我无法添加标题)。

以下代码按预期工作,但永远不会调用ApplyCustomRequestOptions

using System;
using System.Net;
using VDS.RDF.Query;
using VDS.RDF.Storage;

class Program
{
    static void Main(string[] args)
    {
        var endpointUri = new Uri("https://query.wikidata.org/sparql");

        var endpoint = new CustomEndpoint(endpointUri);

        using (var connector = new SparqlConnector(endpoint))
        {
            var result = connector.Query("SELECT * WHERE {?s ?p ?o} LIMIT 1");
        }
    }
}

public class CustomEndpoint : SparqlRemoteEndpoint
{
    public CustomEndpoint(Uri endpointUri) : base(endpointUri) { }

    protected override void ApplyCustomRequestOptions(HttpWebRequest httpRequest)
    {
        // This is never executed.
        base.ApplyCustomRequestOptions(httpRequest);
        // Implementation omitted.
    }
}

这是使用这些方法的正确方法吗?如果不是,那是什么?

BTW这是dotNetRdf 1.0.12,.NET 4.6.1。我尝试了多个SPARQL端点,多个查询(SELECTCONSTRUCT)以及SparqlConnector.Query的多次调用。

1 个答案:

答案 0 :(得分:0)

这是一个错误。我发现了问题并修复了它并提交了PR。您可以在此处跟踪问题的状态:https://github.com/dotnetrdf/dotnetrdf/issues/103