I have been attempting to utilize the .NET Business Connector (AX 2009) within a WCF service hosted in IIS. I have followed all steps required to impersonate the calling identity (Kerberos) within my service, however when my service call attempts to login to AX, I received the following vague error:
Failed to initialize Business connector.
at Microsoft.Dynamics.BusinessConnectorNet.Axapta.Logon(BC_PROXY_ACCOUNT_INFO* pBCProxyAccountInfo, String company, String language, String objectServer, String configuration)
at Microsoft.Dynamics.BusinessConnectorNet.Axapta.Logon(String company, String language, String objectServer, String configuration)
Just for kicks, I modified my code to use the LoginAs method with my credentials hardcoded simply as means to verify if my problem is truly an impersonation issue, or if the .NET Business Connector just outright refuses to function within a Web Service / WCF Service. This of course fails as well, with:
Exception of type 'Microsoft.Dynamics.BusinessConnectorNet.InitializationFailedException' was thrown.
at Microsoft.Dynamics.BusinessConnectorNet.Axapta.Logon(BC_PROXY_ACCOUNT_INFO* pBCProxyAccountInfo, String company, String language, String objectServer, String configuration)
at Microsoft.Dynamics.BusinessConnectorNet.Axapta.LogonUsingBCProxyAccount(_SEC_WINNT_AUTH_IDENTITY_W* pImpersonatedUserAccount, NetworkCredential bcProxyCredentials, String company, String language, String objectServer, String configuration)
at Microsoft.Dynamics.BusinessConnectorNet.Axapta.LogonAs(String user, String domain, NetworkCredential bcProxyCredentials, String company, String language, String objectServer, String configuration)
The function in my WCF service looks like this (I stripped out the irrelevant AX Class/Method call code to reduce the size here)
[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
public string GetTopicList()
{
string axList = "Starting...";
try
{
WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
if (callerWindowsIdentity == null)
{
throw new InvalidOperationException
("The caller cannot be mapped to a Windows identity.");
}
using (callerWindowsIdentity.Impersonate())
{
axList += "Creating Axapta Object...\r\n";
Axapta ax = new Axapta();
string Username = Environment.UserName;
axList += "Impersonated User = " + Username + "\r\n";
ax.Logon(null, null, null, null); // This is where the code fails and jumps into the catch block despite the fact that the impersonated user has Admin rights in AX.
…
ax.Logoff();
axList += "Success!";
}
}
catch (Exception ex)
{
axList += ex.Message + "\r\n" + ex.StackTrace;
}
return axList;
}
Here is some code I wrote to test the call and its results via a WinForms app…
private void TestCall()
{
using ((WindowsIdentity.GetCurrent()).Impersonate())
{
ServiceReference1.Service1Client sv = new ServiceReference1.Service1Client();
string s = sv.GetTopicList();
txtResult.Text = s;
}
}
Has anyone had any success doing this, and if so, I am very interested to know what steps you took to get the .NET Business Connector to successfully login via a Web Service / WCF.
Thanks!