Asp.Net 5 Web Hook

 

首先,然我们来看一下WebHooks是什么。WebHooks是一个协议。它们是HTTP回调技术。并且它们是“用户定义的HTTP回调”。你和 (或) 您的应用程序在有什么事情发生时会发送通知,然后您的 URL 端点在那件事情发生的时候就会 收到一封HTTP 邮件。

--来自Scott Hanselman的博客 ASP.NET WebHooks Receivers 介绍-WebHooks 让其变得便捷

同样是通知机制,WebHook跟SingalR的区别在哪里:

SignalR is for notification within an ASP.NET app using WebSockets. You can exchange event notifications through WebSockets, however it requires a constant network connection.

WebHooks are for event notification across other web applications and other external services. (Think B2B communication). For instance, you can receive a WebHook when someone sends you money to your PayPal account. PayPal fires off a POST request to your predefined URL handler and then your app does something with that notification. You pre-configure everything on the PayPal side first. You also set up an application to handle the incoming POST request. The event notification is "pushed" to you in (near) real-time. No need to hold open a network connection while waiting for events.

The two can be complementary. For example, when you receive the WebHook from PayPal, you can notify a logged in user on your webapp (using SignalR/WebSockets) that money has been received successfully.

TLDR: Event notification across different web applications

-- from Difference between ASP.NET WebHooks and Signal-R

做过微信公众号开发的人应该熟悉WebHook的模式吧。微信要求我们为公众号设定一个回调地址,当有用户向公众号发送消息时,这个回调地址所指的服务器回收到来自微信的消息。这不就是一个WebHook的例子吗?

posted @ 2015-11-27 13:18  排骨虾  阅读(1287)  评论(0编辑  收藏  举报