如何注销Acumatica Web Api用户? [英] How do I log out the Acumatica Web Api user?

查看:88
本文介绍了如何注销Acumatica Web Api用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的测试环境中遇到了一个问题,该环境有两个用户的限制,因为我不断地需要Web API用户登录以同步数据,所以该环境不断引导我。因此,我想问一下是否有一种方法可以使Web API在完成时注销。

I'm running into a problem on our test environment, which has a limit of two users, where it constantly boots me out because the Web API user logs in over and over as needed to sync data. So I thought I'd ask to see if there is a way to get the Web API to log out when it finishes. Is this possible?

推荐答案

什么版本的acumatica?

What version of acumatica?

Acumatica 4.x及以下版本没有注销方法。我要做的是为我的Acumatica方法创建一个单例类,并添加一个通用的 Validate方法,以便它重新使用现有的连接。

Acumatica 4.x and below did not have a method to log off. What I've done is create a singleton class for my Acumatica methods and add a common "Validate" method so it re-uses an existing connection.

类似于以下内容:

    private void Validate(bool forceLogin = false, int trycount = 0)
    {
        if (trycount == 2)
        {
            //throw new AcumaticaException("Could not login to Acumatica Instance");
        }
        if (_container == null || forceLogin)
        {
            _container = new System.Net.CookieContainer();
            if (forceLogin != true)
            {
                forceLogin = true;
            }
        }
        _guruscreen = new Screen
        {
            CookieContainer = _container,
            AllowAutoRedirect = true,
            EnableDecompression = true,
            Timeout = 1000000,
            Url = AcumaticaUrl
        };

        if (forceLogin)
        {
            _guruscreen.Login("webservice", "WebServicePwd");
        }

        try
        {
            _guruscreen.UntypedClear("CW900000");
        }
        catch
        {
            // if session expired, login again and resend request
            Validate(true, trycount++);
        }
    }

然后在调用Export /提交我致电Validate()来查看现有连接是否存在,查看它是否仍处于活动状态,如果不尝试重新连接。

Then in each of my methods before calling the Export/Submit I call Validate() to see if an existing connection exists, see if it's still active and if not try to reconnect.

如果您使用的是Acumatica 5.x,有一种注销方法。

If you are in Acumatica 5.x, there is a logout method.

以下示例

private const string Url = "http://localhost/WebServices_5-0/Soap/DemoService.asmx";
private const string UntypedUrl = "http://localhost/WebServices_5-0/Soap/.asmx";
private const string Login = "xxxxx";
private const string Password = "XXX";

public void ExportStockItems()
{
    Screen context = new Screen();
    context.CookieContainer = new System.Net.CookieContainer();
    context.Url = Url;
    context.Login(Login, Password);

    IN202500Content stockItemsSchema = context.IN202500GetSchema();
    var commands = new Command[]
    {
    stockItemsSchema.StockItemSummary.ServiceCommands.EveryInventoryID,
    stockItemsSchema.StockItemSummary.InventoryID,
    stockItemsSchema.StockItemSummary.Description,
    stockItemsSchema.GeneralSettingsItemDefaults.ItemClass,
    stockItemsSchema.GeneralSettingsUnitOfMeasureBaseUnit.BaseUnit,
    stockItemsSchema.PackagingDimensions.Volume,
    stockItemsSchema.PackagingDimensions.Weight
    };
    var filters = new Filter[]
    {
    new Filter
    {
        Field = new Field 
        {
        ObjectName = stockItemsSchema.StockItemSummary.InventoryID.ObjectName,
        FieldName = "LastModifiedDateTime" 
        },
        Condition = FilterCondition.Less,
        Value = DateTime.Now.ToLongDateString(),
        Operator = FilterOperator.And
    },
    new Filter
    {
        Field = new Field 
        {
        ObjectName = stockItemsSchema.StockItemSummary.ItemStatus.ObjectName,
        FieldName = stockItemsSchema.StockItemSummary.ItemStatus.FieldName 
        },
        Condition = FilterCondition.Equals,
        Value = "Active",
    }
    };
    var items = context.IN202500Export(commands, filters, 0, false, false);

    UntypedDemoServiceRef.Screen untypedContext = new UntypedDemoServiceRef.Screen();
    context.Url = UntypedUrl;
    untypedContext.CookieContainer = context.CookieContainer;
    untypedContext.Logout();
}

这篇关于如何注销Acumatica Web Api用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆