我们可以在 asp.net web services(asmx) 中实现 web-hook 监听器吗?
Can we implement web-hook listener in asp.net web services(asmx)?
我想在我的 asp.net web services(asmx)
中实现网络钩子侦听器。我对此进行了很多搜索,但找不到任何解决方案。
可能吗?
谢谢!
我还没有测试过,但我想大概的思路是这样的:
NotifyService.asmx
<%@ WebService language = "C#" class = "NotifyService" %>
using System;
using System.Web.Services;
using System.Xml.Serialization;
[WebService(Namespace = "http://localhost/")]
public class NotifyService: WebService{
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public String Notify(string name)
{
return "Hello " + name;
}
}
然后就可以通过请求来调用了GET http://localhost/NotifyService.asmx/Notify?name=Dude
根据你的问题,我假设你只需要参考资源就可以开始?如果是:
- ASP.NET WebHooks (https://github.com/aspnet/aspnetwebhooks) 可能是第一个开始的地方。
- 如果您正在寻找有关构建处理聊天的 WebHook 的基本教程。我建议阅读这篇文章 (https://tutorials.botsfloor.com/facebook-chatbot-in-asp-net-2f9379a238b0)
坦率地说,我不确定您在提出问题之前是否付出了足够的努力,因为几次 google 搜索很快就给出了这些结果。还有更多资源可帮助您开始使用 ASP.NET WebHooks。
我是这样做的:(例如,传入的数据是来自服务器的 JSON
格式)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void WebHookDataRecieve() //This method is called from Amazon Simple Notification Service when we receive a bounce.
{
string notification = "";
using (var stream = new MemoryStream())
{
var request = HttpContext.Current.Request;
request.InputStream.Seek(0, SeekOrigin.Begin);
request.InputStream.CopyTo(stream);
notification = Encoding.UTF8.GetString(stream.ToArray());//All of your data will be here in JSON format.
//Simply parse it and access the data.
}
}
这有效。
我想在我的 asp.net web services(asmx)
中实现网络钩子侦听器。我对此进行了很多搜索,但找不到任何解决方案。
可能吗?
谢谢!
我还没有测试过,但我想大概的思路是这样的:
NotifyService.asmx
<%@ WebService language = "C#" class = "NotifyService" %>
using System;
using System.Web.Services;
using System.Xml.Serialization;
[WebService(Namespace = "http://localhost/")]
public class NotifyService: WebService{
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public String Notify(string name)
{
return "Hello " + name;
}
}
然后就可以通过请求来调用了GET http://localhost/NotifyService.asmx/Notify?name=Dude
根据你的问题,我假设你只需要参考资源就可以开始?如果是:
- ASP.NET WebHooks (https://github.com/aspnet/aspnetwebhooks) 可能是第一个开始的地方。
- 如果您正在寻找有关构建处理聊天的 WebHook 的基本教程。我建议阅读这篇文章 (https://tutorials.botsfloor.com/facebook-chatbot-in-asp-net-2f9379a238b0)
坦率地说,我不确定您在提出问题之前是否付出了足够的努力,因为几次 google 搜索很快就给出了这些结果。还有更多资源可帮助您开始使用 ASP.NET WebHooks。
我是这样做的:(例如,传入的数据是来自服务器的 JSON
格式)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void WebHookDataRecieve() //This method is called from Amazon Simple Notification Service when we receive a bounce.
{
string notification = "";
using (var stream = new MemoryStream())
{
var request = HttpContext.Current.Request;
request.InputStream.Seek(0, SeekOrigin.Begin);
request.InputStream.CopyTo(stream);
notification = Encoding.UTF8.GetString(stream.ToArray());//All of your data will be here in JSON format.
//Simply parse it and access the data.
}
}
这有效。