web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Any success using .NET Business Connector within a WCF service??

(0) ShareShare
ReportReport
Posted on by 110
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!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Shashi s Profile Picture
    1,203 on at

    The logon method will use the service account of the applciation pool.The application pool user should be an Ax user.

    can you try to post your code for the LogonAs method.

    This link explains a lot of the LongonAs method: msdn.microsoft.com/.../microsoft.dynamics.businessconnectornet.axapta.logonas.aspx

    I have my WCF service up and running, works like a charm,except the connection to Ax dosent get destroyed unlike a regular exe application connecting with the .Net business connector

  • Community Member Profile Picture
    on at

    Did you find any solution to close connection from WCF to AX?

    For testing I'm using BasicHttpBinding.

    I tried everything:

    ax.Logoff(), ax.Dispose() in every posible option and it doesn't end connection.

    I destroy every object I've created which using ax and still the same:

    e.g.

    BCNC = new System.Net.NetworkCredential(,,)

    ax = new Axapta();

    ax.LogonAs(BCNC.UserName, BCNC.Domain, BCNC, AXComapny, "", AXServer, "");

    AXClass = ax.CreateAxaptaObject("axclass");

    AXClass.Call("axclass.metod");

    AXClass.Dispose();

    ax.Logoff();

    ax.Dispose();  

    Does anybody now how to fix this problem? How to close BC session to AX from .NET side?

    Regards

    Maciek Sondej

  • Shashi s Profile Picture
    1,203 on at

    If the axapta object is created within the WCF service, upon logoff the Ax session will end.

    If you are using a static variable (for the axapta object for the entire WCF service) then the ax session will only end when the Application pool is recycled.

    I have a test project to prove it.

    Ping me and i can send you a project which shows the difference.

  • Community Member Profile Picture
    on at

    I know how in theory it should work, what is the difference between static, global and local variables and how long should the 'live'.

    Finally I reinstalled IIS and .NET (I reinstalled whole environment) and it started to work. Somehow .NET garbage collector wasn't doing his work.

    Regards

    Maciek Sondej

  • Evgin Profile Picture
    5 on at

    Hello SHASHI,

    if you still have this code can you share with me ?

    i am in a sittuation that

    axapta web users  reaches 2000 limit every day   and we

    have to restart  2  iis  server and 1 server that  axapta running.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans