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



我正在尝试将自定义标头添加到 HTTP 要求集 SPARQL 端点连接器问题。连接器可以使用自定义远程终结点,该终结点继承了我可以重写的 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.
    }
}

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

顺便说一句,这是dotNetRdf 1.0.12,.NET 4.6.1。我尝试了多个SPARQL端点,多个查询(SELECTCONSTRUCT(和SparqlConnector.Query的多次调用。

这是一个

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

最新更新