如何注销 Acumatica Web Api 用户?
How do I log out the Acumatica Web Api user?
我 运行 在我们的测试环境中遇到了一个问题,它有两个用户的限制,它不断地引导我退出,因为 Web API 用户一遍又一遍地登录需要同步数据。所以我想我会问问是否有办法让 Web API 在完成时注销。这可能吗?
acumatica 是什么版本?
Acumatica 4.x 及以下版本没有注销方法。我所做的是为我的 Acumatica 方法创建一个单例 class 并添加一个通用 "Validate" 方法,以便它重新使用现有连接。
类似于以下内容:
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/Submit 之前的每个方法中,我调用 Validate() 以查看是否存在现有连接,查看它是否仍处于活动状态,如果不存在则尝试重新连接。
如果你在 Acumatica 5.x,有一个注销方法。
下面是其中的一个示例
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();
}
我 运行 在我们的测试环境中遇到了一个问题,它有两个用户的限制,它不断地引导我退出,因为 Web API 用户一遍又一遍地登录需要同步数据。所以我想我会问问是否有办法让 Web API 在完成时注销。这可能吗?
acumatica 是什么版本?
Acumatica 4.x 及以下版本没有注销方法。我所做的是为我的 Acumatica 方法创建一个单例 class 并添加一个通用 "Validate" 方法,以便它重新使用现有连接。
类似于以下内容:
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/Submit 之前的每个方法中,我调用 Validate() 以查看是否存在现有连接,查看它是否仍处于活动状态,如果不存在则尝试重新连接。
如果你在 Acumatica 5.x,有一个注销方法。
下面是其中的一个示例
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();
}