热门标签 | 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反序列化。


推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • This guide provides a comprehensive step-by-step approach to successfully installing the MongoDB PHP driver on XAMPP for macOS, ensuring a smooth and efficient setup process. ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 尽管使用TensorFlow和PyTorch等成熟框架可以显著降低实现递归神经网络(RNN)的门槛,但对于初学者来说,理解其底层原理至关重要。本文将引导您使用NumPy从头构建一个用于自然语言处理(NLP)的RNN模型。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • 深入解析:手把手教你构建决策树算法
    本文详细介绍了机器学习中广泛应用的决策树算法,通过天气数据集的实例演示了ID3和CART算法的手动推导过程。文章长度约2000字,建议阅读时间5分钟。 ... [详细]
  • 尽管某些细分市场如WAN优化表现不佳,但全球运营商路由器和交换机市场持续增长。根据最新研究,该市场预计在2023年达到202亿美元的规模。 ... [详细]
  • 本章将深入探讨移动 UI 设计的核心原则,帮助开发者构建简洁、高效且用户友好的界面。通过学习设计规则和用户体验优化技巧,您将能够创建出既美观又实用的移动应用。 ... [详细]
  • 本文介绍了如何通过 Maven 依赖引入 SQLiteJDBC 和 HikariCP 包,从而在 Java 应用中高效地连接和操作 SQLite 数据库。文章提供了详细的代码示例,并解释了每个步骤的实现细节。 ... [详细]
  • 本文介绍了在Windows环境下使用pydoc工具的方法,并详细解释了如何通过命令行和浏览器查看Python内置函数的文档。此外,还提供了关于raw_input和open函数的具体用法和功能说明。 ... [详细]
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社区 版权所有