-->

如何使Acumatica传出请求或网络挂接?(How to make outgoing reques

2019-09-25 17:51发布

我与整合的Acumatica应用Asp.NET需要更新发货信息(跟踪#,载体等),当它在Acumatica变为可用。 有没有办法有Acumatica通话时创建装运我的Asp.NET应用程序的终点? 我已经经历了很多的文档(可搜索的在这里 ),但我还没有碰到过任何东西,从Acumatica 发送信息到其他网络服务。

理想情况下,呼出将在有效载荷发送出货对象。

Answer 1:

在我的答案我想你知道如何调用从C#代码一些外部服务,并为您的是一个挑战,如何从Acumatica发送通知。 我建议你来扩展每个Acumatica图,从中你希望当对象在DB是持续发送通知各persist方法。 IMHO此最好的选择是重写方法持续存在(顺便说一句,它覆盖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.
  }


Answer 2:

这是不可用的时候你问这个问题,但推送通知似乎是你在寻找什么:

帮助- 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



Answer 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));
}


文章来源: How to make outgoing request or webhook in Acumatica?
标签: acumatica