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)

AX 2012 app.config is ignored when calling .NET code from AX

(0) ShareShare
ReportReport
Posted on by

Hi guys,

I have to get some data from a web service. So I have created a simple console application to test the server. That worked.

Then I have create a new class library  project and built it in same way as my console application (added same WSDL manually, copy&pasted some code).

Then after adding the project to AX AOT and setting it up (deployment properties etc.), restarting AOS, generating CIL and all other "maintenance" tasks just to be sure, I have tried to call the code from X++ which is calling the web service to retrieve data. But as soon as the debugger gets to the line where the web service client object is created (which works fine in the console application) I get the exception:

"Could not find default endpoint element that references contract 'xxxxxx.xxxxx' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element"

I have found this post which describes the same problem that AX ignores the .NET configuration files since the Ax32serv.exe or Ax32.exe are "custom" executables.
http://community.dynamics.com/ax/f/33/t/83437.aspx

Similar problem is described here (is not AX related, but sounds similar):
http://stackoverflow.com/questions/3188965/could-not-find-endpoint-element-with-name 

Before going this way (providing the parameters as C# objects and not XML) I checked with some guys and they say that they already have VS projects added and being used in X++ and the config file is used; otherwise their process wouldn't work.
I am not sure about it and weren't able to test it myself yet.

In general, as far as I know .NET runtime creates the config file in the same directory as the exe file and names it xxxx.exe.config.
If you look into the bin directory of the AOS, you will find such file: Ax32Serv.exe.config. But it is only for the standard services.

When you look into the \bin\VSAssemblies folder, you will see for every VS project there are two files:
MyCode.dll
MyCode.dll.config

So I expect when running the code AX should use this config. But I don't know if it happens.

I am quite sure my app.config is correct (at least it works in the console application).
And also the other two posts indicate that AX ignores the config files created and deployed from VS projects.

Have you guys had same problems? How would you approach this? 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    In general, .net will only load the .config from the process host, in this case the AX32 client config or the server config (based on what tier your code runs on). So in regular .NEt, you'd be required to copy/paste your config data into the process host's existing config. HOWEVER! :-)

    This is an older article and I haven't tried it on R2 or R3 but I'm assuming it's still valid:

    daxmusings.codecrib.com/.../consuming-external-webservices-in-ax.html

    Basically, you can use the AIF utilities to load your "custom" config file on the fly.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Have you created the client through AifUtil::createServiceClient()?

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Joris and Martin,

    Thanks for the help. Actually, I found almost the same answers in TechNet and by asking my colleagues meanwhile.

    In one case it works because my colleague consumes the web service directly from X++ and before doing so creates the client through:

    AifUtil::createServiceClient()

    so the config is loaded.

    But in my case I am consuming the web service in C# so I assume AifUtil::createServiceClient() is useless here?

    In this TechNet article:

    technet.microsoft.com/.../hh500185.aspx

    MS recommends to use ConfigurationChannelFactory in such cases. I will try this maybe.

    But what I did already is to use .NET BasicHttpBinding object, setting all the parameters and passing it along with the EndpointAddress object when creating the web service client object in C#.

    Looks like it works. Although I think it is not the most beautiful solution. Maybe using ConfigurationChannelFactory is better.

  • Community Member Profile Picture
    on at

    Another idea (haven't tested it though): add (copy&paste from the app.config generated automatically) the required config sections to the Ax32Serv.exe.config file.

    However it doesn't feel good to touch this automatically generated file. I am not sure if it might be overwritten at some point by AX.

  • Vishal Dhavgaye Profile Picture
    405 on at

    Hi Waldemar,

    I have same issue, how did you solved your issue?

  • Community Member Profile Picture
    on at

    Hi Vishal,

    It was quite long time ago, but if you read the entire thread, you will see that I marked one answer as verified (see 21 May 2014 11:35 AM). I wouldn't remember more than than and unfortunately don't have access to the code anymore.

    Hope that helps in any way.

    Regards,
    Waldemar

  • Vishal Dhavgaye Profile Picture
    405 on at

    Thank you.

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