【问题标题】:How to make outgoing request or webhook in Acumatica?如何在 Acumatica 中发出传出请求或 webhook?
【发布时间】:2018-09-13 06:18:40
【问题描述】:

我正在将一个 Asp.NET 应用程序与 Acumatica 集成,该应用程序需要在 Acumatica 中可用时更新运输信息(跟踪号、承运人等)。有没有办法让 Acumatica 在创建货件时调用我的 Asp.NET 应用程序上的端点?我搜索了很多文档(可用here),但我没有遇到任何可以将OUT信息从 Acumatica 发送到另一个 Web 服务的内容。

理想情况下,此呼出电话将在有效负载中发送货件对象。

【问题讨论】:

  • Acumatica 是否应该立即发送消息?
  • @YuraZaletskyy,是的,那将是理想的。几乎就像一个在运输信息更新事件上触发的 webhook。
  • Acumatica 中 PushNotifications 的功能正在开发中,我们希望它会尽快发布。

标签: acumatica


【解决方案1】:

当您提出问题时,此功能不可用,但 推送通知 似乎正是您要查找的内容:

帮助 - https://help.acumatica.com/(W(9))/Main?ScreenId=ShowWiki&pageid=d8d2835f-5450-4b83-852e-dbadd76a5af8

演示文稿 - https://adn.acumatica.com/content/uploads/2018/05/Push-Notifications.pdf

【讨论】:

    【解决方案2】:

    在我的回答中,我想您知道如何从 C# 代码调用一些外部服务,而对于您来说,如何从 Acumatica 发送通知是一个挑战。 我建议您在每个 Acumatica 图中扩展每个 Persist 方法,当对象持久保存在数据库中时,您希望从中发送通知。恕我直言,最好的选择是覆盖方法persist(顺便说一句,它覆盖persist方法在T300中有很好的描述)。在扩展类的代码中,您可以执行以下操作:

    public void Persist(PersistDelegate baseMethod) 
    { 
       baseMethod(); // calling this method will preserve your changes in db
    
       //here should go your code, that will send push/pop/delete etc web request into your asp.net application. Or in other words your web hook.
      }
    

    【讨论】:

    • 你知道我在哪里可以找到关于如何修改 Acumatica 图表的课程文档吗?另外,我可以让被持久化的对象与网络请求一起发送吗?
    • 您已经在问题中提到了链接。我建议你先看T100课程的前几章,然后在pdf的T300课程中你会看到如何扩展类库
    • 在以下链接您可以看到更多详细信息:blog.zaletskyy.com/how-to-start-with-acumatica-development。如果您觉得我的帖子有用,请将我的回答标记为已接受 plz
    • 我没有机会对此进行全面测试,但您的博文很有帮助。谢谢
    【解决方案3】:

    如果您没有 Acumatica 2017R2,那么您必须创建自己的扩展项目,然后您可以从您的 Acumatica 代码中调用它:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Net;
    
    namespace MyApp
    {
        public static class Utility
        {
            private static WebRequest CreateRequest(string url, Dictionary headers)
            {
                if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    WebRequest req = WebRequest.Create(url);
                    if (headers != null)
                    {
                        foreach (var header in headers)
                        {
                            if (!WebHeaderCollection.IsRestricted(header.Key))
                            {
                                req.Headers.Add(header.Key, header.Value);
                            }
                        }
                    }
                    return req;
                }
                else
                {
                    throw(new ArgumentException("Invalid URL provided.", "url"));
                }
            }
            public static string MakeRequest(string url, Dictionary headers = null)
            {
                WebResponse resp = CreateRequest(url, headers).GetResponse();
                StreamReader reader = new StreamReader(resp.GetResponseStream());
                string response = reader.ReadToEnd();
                reader.Close();
                resp.Close();
                return response;
            }
            public static byte[] MakeRequestInBytes(string url, Dictionary headers = null)
            {
                byte[] rb = null;
                WebResponse resp = CreateRequest(url, headers).GetResponse();
                using (BinaryReader br = new BinaryReader(resp.GetResponseStream()))
                {
                    rb = br.ReadBytes((int)resp.ContentLength);
                    br.Close();
                }
                resp.Close();
                return rb;
            }
        }
    }

    你可以这样称呼它:

    try
    {
      Utility.MakeRequest(theUrl, anyHeadersYouNeed);
    }
    catch(System.Net.WebException ex)
    {
      throw(new PXException("There was an error.", ex));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      相关资源
      最近更新 更多