验证多线程C#失败 [英] Authentication failing with multiple threads c#

查看:226
本文介绍了验证多线程C#失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个Web应用程序提供了一些数据库操作。该系统还需要与不同databases.The问题工作能力是在数据库中的某些字段必须从一个RESTful API数据进行更新。要执行这些更新,我用一个Quartz.NET时间表,使一个工作,每一个需要updated.This工作检查是否需要更新相关的数据库表。如果是的话,它就会从REST的服务的信息。当我不使用多线程,有与访问REST-serivce没有问题。但是当我使用Quartz.net,服务器返回401错误对于某些请求。此行为是inconstistent,不会总是发生。我使用RestSharper使这些电话与摘要式身份验证的自定义验证器。我得到这个解决方案在这里:结果
HTTP ://www.ifjeffcandoit.com/2013/05/16/digest-authentication-with-restsharp/

I'm currently writing a web application that provides some database manipulation. The system also needs to be capable working with different databases.The problem is that certain fields in the database have to be updated with data from a RESTful api. To perform these updates, I use a Quartz.NET schedule that makes a job for every table that needs to be updated.This job checks if it needs to update the relevant database. If it does, it gets the information from the REST-service. When I don't use multithreading, there are no problems with accessing the REST-serivce. But when I use Quartz.net, the server returns a 401 error for some requests. This behavior is inconstistent and doesn't always happen. I'm using RestSharper to make these calls with a custom Authenticator for digest authentication. I got this solution here:
http://www.ifjeffcandoit.com/2013/05/16/digest-authentication-with-restsharp/

我也用在了AUTH定影液。后

I also use the auth fixer in that post.

创建工作:

            foreach (KeyValuePair<string, int> tabel in DataParser.getAllTabellenMetRefresh())
        {
            // define the job and tie it to our class
            IJobDetail job = JobBuilder.Create<LocatieUpdater>()
                .WithIdentity("dbUpdaterJob"+count, "group1")
                .UsingJobData("type", tabel.Key)
                .Build();

            // Trigger the job to run now, and then every x seconds
            ITrigger trigger = TriggerBuilder.Create()
              .WithIdentity("myTrigger"+count, "group1")
              .StartNow()
              .WithSimpleSchedule(x => x
                  .WithIntervalInMinutes(tabel.Value)
                  .RepeatForever())
              .Build();
            sched.ScheduleJob(job, trigger);

在这段代码的响应接收401。

The response in this piece of code receives the 401.

var client = new RestClient(gegevens["Url"]);

        client.Authenticator = new DigestAuthenticator(ConfigAcces.getCredentials()[0], ConfigAcces.getCredentials()[1]);


        var request = new RestRequest(gegevens["request"], Method.GET);
        request.AddParameter("fields", "all");
        request.AddParameter(velden["TagId"], id);
        IRestResponse response = client.Execute(request);



我看着与小提琴手的要求,但并没有真正看到什么有用的。任何帮助或提示将是非常欢迎的。
提前感谢!

I looked at the request with fiddler, but didn't really see anything usefull. Any help or tips would be very welcome. Thanks in advance!

推荐答案

不能完全确定这是如何固定的,但所有的认证似乎通过禁用工作使用SyncronisationContext和制作任务的方法等。

Not entirely sure how this fixed it, but all authentication seems to work by disabling the use of the SyncronisationContext and making the method wait for the task.

  var request = new RestRequest(gegevens["request"], Method.GET);
    request.AddParameter("fields", "all");
    request.AddParameter(velden["TagId"], id);
        client.UseSynchronizationContext = false;
        IRestResponse response = await client.ExecuteTaskAsync(request);

这篇关于验证多线程C#失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆