Azure App Services:WebJob如何向WebAPI发送响应?

时间:2017-09-25 14:29:20

标签: c# azure asp.net-web-api azure-web-app-service

在Azure中,我有 WebAPI WebJob 。 WebAPI将消息发送到 Azure Service Bus 队列,WebJob是该队列中唯一的订户。当WebJob完成处理作业时,如何将响应消息传递给WebAPI?

1 个答案:

答案 0 :(得分:0)

您可以创建一个API来接受来自WebJob的响应。以下代码供您参考。

public class WebJobResponseController : ApiController
{
    public string Get(string token, string value)
    {
        //use the token to validate the webjob, use the value to post any data which you want to send to API
        return "success";
    }
}

在WebJob端,处理完作业后,您只需向上层API发送请求即可。以下代码供您参考。

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("URL of your API");
await client.GetAsync("WebJobResponse?token=token1&value=value1");