2017-05-04 78 views
4

我正在写Job Scheduler使用Quartz库在C#。我的要求是,如果符合商业条件,我需要拨打Apple服务器。如何从类库C#中的类进行http调用?

这是我的计划看起来像: -

public class CustomerJob : BaseJob 
{ 
    private readonly ICustomerSchedulerService _customerSchedulerService; 

    public CustomerJob (ICustomerSchedulerService customerSchedulerService) 
    { 
     _customerSchedulerService= customerSchedulerService; 
    } 
    public override void Execute(IJobExecutionContext context) 
    { 
     var customers = _customerSchedulerService.CheckExpiredTask(); 
     foreach(var customer in customers) 
     { 
      //I need to make a post request to apple server for each customer 
      //something like below however there is no HttpClient() available in this class 
     //var client = new HttpClient();  
     //client.PostAsync("https://sandbox.itunes.apple.com/verifyReceipt", customer)); 
     } 
     base.Execute(context); 
    } 
} 

那么如何解决这个问题?要求

注: -
我不喜欢这个进入API或基于Web的项目,因为这个调度程序将来自网络& API团队&调用其他(一个或多个)。

谢谢。

+1

如果HttpClient不可用,那么确保你引用了正确的类库,并在你的类的顶部有正确的'using namespace'语句。从类库调用服务与从任何其他地方调用服务没有区别。 – mason

回答

1

如果它在您的班级中不可用,您可能只需在顶部添加引用或稍微更改您的行。

new HttpClient();替换为new System.Net.Http.HttpClient();。这要么工作或Visual Studio(如果这是你使用的是什么)应该告诉你潜在的修复:)

希望这会有所帮助,如果没有答复,我也许能找出你的下一个问题:)

+0

'HttpClient'在类库类型项目中不可用。 –

+1

您是否无法为其添加nuget软件包? – Jaxi

+0

我可以从https://www.nuget.org/packages/microsoft.net.http/获取。但你确定这是正确的方式吗?因为我不是..谢谢 –