【问题标题】:Azure App Services: How can a WebJob send a response to WebAPI?Azure 应用服务:WebJob 如何向 WebAPI 发送响应?
【发布时间】:2017-09-25 14:29:19
【问题描述】:

在 Azure 中,我有一个 WebAPI 和一个 WebJob。 WebAPI 将消息发送到 Azure 服务总线 队列,而 WebJob 是该队列的唯一订阅者。当 WebJob 完成处理作业时,它如何将响应消息传递给 WebAPI?

【问题讨论】:

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


    【解决方案1】:

    您可以创建一个 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");
    

    【讨论】:

    • 有什么更新吗?如果您对此主题还有其他问题,请随时告诉我。
    猜你喜欢
    • 1970-01-01
    • 2017-02-18
    • 2020-01-19
    • 2022-01-09
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多