【问题标题】:GenericJson WebHook returns Bad RequestGenericJson WebHook 返回错误请求
【发布时间】:2018-11-13 21:57:39
【问题描述】:

我正在尝试为 BuildCompleted 事件实现 WebHook。从 Web 界面测试服务挂钩时,我遇到了错误:Bad Request (400)。事件日志或 IIS 日志文件中似乎没有关于错误的详细信息。 WebApiConfig 中的 Register 函数被命中,但我的 WebHook 中的构造函数或 ExecuteAsync 未命中。

任何帮助将不胜感激!我敢肯定,我似乎能看到自己是微不足道的。

我的设置包括本地 TFS 2018 Update 2 服务器和一个单独的带有用于 WebHook 的 IIS 的 Windwos Server 2012。我将 Global.asax 和 web.config 部署到 wwwroot 并将程序集部署到 wwwroot/bin。

网址:http://MYSERVER/api/webhooks/incoming/genericjson?code=83699ec7c1d794c0c780e49a5c72972590571fd8

web.config:

...
<appSettings>
    <add key="MS_WebHookReceiverSecret_GenericJson" value="83699ec7c1d794c0c780e49a5c72972590571fd8" />
</appSettings>
...

WebHookHandler:

public class GenericJsonWebHookHandler : WebHookHandler
{
    public GenericJsonWebHookHandler()
    {
        this.Receiver = GenericJsonWebHookReceiver.ReceiverName;
    }

    public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
    {
        return Task.FromResult(true);
    }
}

WebApiConfig:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new {id = RouteParameter.Optional}
        );

        // Initialize GenericJson WebHook receiver
        config.InitializeReceiveGenericJsonWebHooks();
    }
}

Global.asax.cs

public class Global : HttpApplication
{
    protected void Application_Start()
    {
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }
}

【问题讨论】:

  • 您的服务在隔离测试时是否正常工作?
  • 隔离?我还没有向 WebHook 添加任何有意义的东西。
  • 您已经添加了足够多的内容,以至于您已经部署了它,但从 VSTS 调用它时出现错误。当你在本地调用它时,你会得到同样的错误吗?您是否尝试过附加调试器并在向其发布数据时单步执行?基本调试步骤。
  • 我已经对日志文件进行了一些简单的写入,并调用了 Register 函数,但我的 WebHook 类中的构造函数和 ExecuteAsync 没有。我将尝试在本地设置 WebHook,以便我可以附加调试器。我确信我刚刚错过了某个地方的日志文件,其中包含详细的错误消息来帮助我。
  • 从我的测试应用程序本地运行服务。当针对 TFS 的相同服务器服务时,相同的应用程序会收到“错误请求”。我将尝试直接在服务器上设置调试会话。

标签: tfs webhooks


【解决方案1】:

这只是需要 https 的 GenericJsonWebHookReceiver 的问题,这实际上是由文档指定的。

TFS 服务挂钩添加屏幕只推荐 https:

This answer 让我仔细查看了对服务的 GetResponse 调用的异常中的响应。

{"Message":"WebHook 接收器 'GenericJsonWebHookReceiver' 需要 HTTPS 才能保证安全。请注册一个类型为 'https' 的 WebHook URI。"}

【讨论】:

    猜你喜欢
    • 2019-11-12
    • 2019-03-11
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多