【问题标题】:Where to handle callback when using Forge Webhooks : server or client side?使用 Forge Webhooks 时在哪里处理回调:服务器端还是客户端?
【发布时间】:2019-03-15 08:29:51
【问题描述】:

我正在尝试使用 Forge Webhooks API 通过 Model Derivative API 监控我的模型的翻译进度。 我用:

  • 服务器端的 C# Web ApiControllers
  • 客户端的jQuery/JS

我不确定在哪里处理来自 Webhooks API 的回调。我开始在 C# ApiController(服务器端)中编写回调接收器:

    [HttpPost]
    [Route("api/webhook/callback")]
    public HttpResponseMessage WebhookCallback(dynamic info)
    {
        string urn = info.resourceUrn;

        // do things

        // redirect to root
        HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.Moved /* force redirect */);
        res.Headers.Location = new Uri("/", UriKind.Relative); // back to / (root, default)

        return res;
    }

但后来我意识到我不能从这个 Controller 方法执行 JS 客户端函数,例如在查看器中显示模型。

我需要在JS客户端部分编写回调接收器吗?如果有,怎么做?

提前感谢您的帮助。

【问题讨论】:

    标签: autodesk-forge autodesk-webhooks


    【解决方案1】:

    webhook 需要调用一个稳定的 URL,所以在你的服务器端,然后调用你的客户端(例如使用 websocket

    我们有一个 .NET 示例 here,抱歉它还没有实现 websocket

    【讨论】:

    • 你会建议 SignalR 实现 websocket 吗?恐怕我的 prod 服务器将在 Windows Server 2008 R2 上,所以它不支持 websockets。
    • 从我在asp.net/signalr阅读的内容看来是可能的,Forge对此没有限制或限制,您可以为它选择最好的技术/库
    • 在支持的平台部分,您可以阅读“请注意,SignalR 需要使用 WebSockets、Windows Server 2012、Windows Server 2016 或 Windows 8”。
    猜你喜欢
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 2011-01-01
    • 2014-02-20
    • 2012-01-11
    相关资源
    最近更新 更多