热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何为.NetCore手动设置WebHookReceiver?-HowtosetupWebHookReceivermanuallyfor.NetCore?

ImtryingtosetuptheWebHookHandlertoReceiveJsonDatafor.NetCoreproject.IknowhowtheWe

I'm trying to setup the WebHookHandler to Receive Json Data for .Net Core project. I know how the Webhook works theoritically.

我正在尝试设置WebHookHandler以接收.Net Core项目的Json数据。我知道Webhook如何在理论上运作。

There is a good amount of information available for Receiving WebHooks but the sample source code. But I need an example for .Net Core?

有大量可用于接收WebHooks的信息,但是示例源代码。但是我需要一个.Net Core的例子吗?

3 个解决方案

#1


1  

.NET Core does not support WebHooks at the moment https://github.com/aspnet/WebHooks/issues/5

.NET Core目前不支持WebHooks https://github.com/aspnet/WebHooks/issues/5

#2


3  

We do want to support WebHooks for ASP.NET Core but it is still in the works. In the mean time, you might be able to look at the handler code and do something similar for ASP.NET Core.

我们确实希望支持WebHooks for ASP.NET Core,但它仍在开发中。与此同时,您可以查看处理程序代码并为ASP.NET Core执行类似的操作。

Hope this helps!

希望这可以帮助!

Henrik

亨里克

#3


1  

Here's a very basic example which I got work with Azure Alerts:

这是我使用Azure警报的一个非常基本的示例:

using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ApplicationInsightsMonitor.Controllers
{
    [Produces("application/json")]
    [Route("api/alerts")]
    public class AlertController : Controller
    {
        [HttpPost]
        public async Task Post([FromBody] AIPayloadModel payload)
        {
            if (payload == default(AIPayloadModel))
            {
                return NotFound();
            }

            // Save to database

            return Ok();
        }
    }

    public class AIPayloadModel
    {
        public enum AIPayloadStatus
        {
            Activated,
            Resolved
        }

        public class AIPayloadContextModel
        {
            public enum AIConditionType
            {
                Metric,
                Event
            }

            public enum AIMetricUnit
            {
                Bytes,
                BytesPerSecond,
                Count,
                CountPerSecond,
                Percent,
                Seconds
            }

            public enum AIAggregation
            {
                Average,
                Last,
                Maximum,
                Minimum,
                None,
                Total
            }

            public class AICondition
            {

                [JsonProperty("metricName")]
                public String Name { get; set; }

                [JsonProperty("metricUnit")]
                public AIMetricUnit Units { get; set; }

                [JsonProperty("metricValue")]
                public Decimal Value { get; set; }

                [JsonProperty("threshold")]
                public Decimal Threshold { get; set; }

                [JsonProperty("windowSize")]
                public TimeSpan WindowSize { get; set; }

                [JsonProperty("timeAggregation")]
                public AIAggregation Aggregation { get; set; }

                [JsonProperty("operator")]
                public String Operator { get; set; }
            }

            [JsonProperty("timestamp")]
            public DateTime Time { get; set; }

            [JsonProperty("id")]
            public String Id { get; set; }

            [JsonProperty("name")]
            public String Name { get; set; }

            [JsonProperty("description")]
            public String Description { get; set; }

            [JsonProperty("conditionType")]
            public AIConditionType ConditionType { get; set; }

            [JsonProperty("condition")]
            public AICondition Condition { get; set; }

            [JsonProperty("subscriptionId")]
            public String SubscriptionId { get; set; }

            [JsonProperty("resourceGroupName")]
            public String ResourceGroupName { get; set; }

            [JsonProperty("resourceGroupType")]
            public String ResourceGroupType { get; set; }

            [JsonProperty("resourceName")]
            public String ResourceName { get; set; }

            [JsonProperty("resourceType")]
            public String ResourceType { get; set; }

            [JsonProperty("resourceRegion")]
            public String ResourceRegion { get; set; }

            [JsonProperty("portalLink")]
            public String PortalLink { get; set; }
        }

        [JsonProperty(PropertyName = "status")]
        public AIPayloadStatus Status { get; set; }

        [JsonProperty(PropertyName = "context")]
        public AIPayloadContextModel Context { get; set; }

        [JsonProperty(PropertyName = "properties")]
        public Dictionary Properties { get; set; } = new Dictionary();
    }
}

The key is using [FromBody] on the parameter and having exactly the right JSON deserialization in your model.

关键是在参数上使用[FromBody]并在模型中具有正确的JSON反序列化。


推荐阅读
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文介绍如何使用阿里云的fastjson库解析包含时间戳、IP地址和参数等信息的JSON格式文本,并进行数据处理和保存。 ... [详细]
  • ASP.NET MVC中Area机制的实现与优化
    本文探讨了在ASP.NET MVC框架中,如何通过Area机制有效地组织和管理大规模应用程序的不同功能模块。通过合理的文件夹结构和命名规则,开发人员可以更高效地管理和扩展项目。 ... [详细]
  • 本文详细探讨了JDBC(Java数据库连接)的内部机制,重点分析其作为服务提供者接口(SPI)框架的应用。通过类图和代码示例,展示了JDBC如何注册驱动程序、建立数据库连接以及执行SQL查询的过程。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 技术分享:从动态网站提取站点密钥的解决方案
    本文探讨了如何从动态网站中提取站点密钥,特别是针对验证码(reCAPTCHA)的处理方法。通过结合Selenium和requests库,提供了详细的代码示例和优化建议。 ... [详细]
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • 在前两篇文章中,我们探讨了 ControllerDescriptor 和 ActionDescriptor 这两个描述对象,分别对应控制器和操作方法。本文将基于 MVC3 源码进一步分析 ParameterDescriptor,即用于描述 Action 方法参数的对象,并详细介绍其工作原理。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 本文介绍如何使用 NSTimer 实现倒计时功能,详细讲解了初始化方法、参数配置以及具体实现步骤。通过示例代码展示如何创建和管理定时器,确保在指定时间间隔内执行特定任务。 ... [详细]
  • 本文介绍了如何通过 Maven 依赖引入 SQLiteJDBC 和 HikariCP 包,从而在 Java 应用中高效地连接和操作 SQLite 数据库。文章提供了详细的代码示例,并解释了每个步骤的实现细节。 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
  • 基因组浏览器中的Wig格式解析
    本文详细介绍了Wiggle(Wig)格式及其在基因组浏览器中的应用,涵盖variableStep和fixedStep两种主要格式的特点、适用场景及具体使用方法。同时,还提供了关于数据值和自定义参数的补充信息。 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
author-avatar
奇国的雪儿
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有