使使用Dynamics AX商务连接器连接AX的网站正常运行,但有时用户未注销。
这是我的代码:
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
try
{
DynAx.Logon(null, null, null, null);
//Execute some methods
DynAx.Logoff();
}
catch (Exception ex)
{
DynAx.Logoff();
}
并且在斧头中,我可以看到用户登录。有时再次发生这种情况,这就是为什么我不知道可能是谁的原因。也许Dispose()方法更好?。
感谢您抽出宝贵的时间阅读本文档。
登录/注销对我来说是正确的,但是如果您说有时无效,则原因很可能是以下原因之一:
//Execute some methods
部分中发生的任何事情都可能锁定或阻止注销。在我的AX2012R3环境中,我可以一次又一次地成功运行以下PowerShell
代码。这将我引向上述原因之一。
Add-Type -Path "C:\Program Files\Microsoft Dynamics AX\60\BusinessConnector\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"
$ax = new-object Microsoft.Dynamics.BusinessConnectorNet.Axapta
$ax.logon($null, $null, $null, $null)
$b = $ax.CreateAxaptaRecord("userinfo")
$array = New-Object System.Collections.ArrayList
$b.ExecuteStmt("select id from %1")
while($b.found){
$array.add($b.get_field("id")) | out-null
$b.next() | out-null
}
$array | Format-Table -AutoSize
$ax.Logoff()
$ax.Dispose()
尝试使用此代码,这是Microsoft参考,这里的链接(对我而言很好用)
private void button1_Click(object sender, EventArgs e)
{
// Create an instance of the Axapta class.
Axapta DynAx = new Axapta();
// Add the proxy user.
// Replace the ProxyUserID and password parameters with the
// proxy user name and password that you specified
// in the Business Connector Proxy.
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserID", "password");
string strUserName = "ProxyUserID";
// Test the connection to the .NET Business Connector.
try
{
DynAx.LogonAs(strUserName.Trim(), "", nc, "", "", "", "");
MessageBox.Show("Success");
DynAx.Logoff();
MessageBox.Show("Logoff completed.");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show(ex.Message);
}
}