Pages

Monday, February 2, 2015

How to refresh AX WSDL configuration from a command prompt

My build/release process is almost entirely automated, except for one step, where we refresh the WSDL/WCF configuration.  So far, I've only been able to do it conventionally with the mouse.


After getting pointed in the right direction by Martin Dráb, I wrote a little command line tool in C# that you can incorporate into your build scripts that should refresh your WCF configuration in your AXC file automatically.

It has one dependency on the AX client configuration tool obviously, which is located at:
C:\Program Files\Microsoft Dynamics AX\60\BusinessConnector\Bin\AxCliCfg.exe

Usage: RefreshAXCConfig.exe <axc file> <aos name> <WSDL Port>
Example: RefreshAXCConfig.exe C:\CUS.axc DevAOS 8101

The only caveat that I'm now realizing as of typing this up, is it uses RegEx to find/replace in the AXC file, so it requires you to have refreshed your WCF at least once, otherwise the RegEx won't find what to replace.

The C# code is simple below, and make sure to add the reference to AxCliCfg.exe.  Happy DAX'ing and hopefully this helps someone.  I've also saved the ZIP'd executable to my OneDrive.  You will need to copy the AxCliCfg to the same local directory in order for it to work.

Link to compiled zipped executable for those who don't feel like typing up themselves.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml;
using Microsoft.Dynamics.Configuration;

namespace RefreshAXCConfig
{
    class Program
    {
        static void Main(string[] args)
        {
            Tuple<Guid, string> result;
            string axcFile;
            string strAOS;
            int intWSDLPort;
            
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: RefreshAXCConfig.exe <axc file> <aos name> <WSDL Port>");
                Console.WriteLine("Example: RefreshAXCConfig.exe CUS.axc Dev-vwaos05 8101");
                return;
            }

            try
            {
                axcFile = args[0];
                strAOS = args[1];
                if (int.TryParse(args[2], out intWSDLPort) == true)
                {
                    result = FormRegenerateWcfDialog.GetConfigurationAsString(strAOS, intWSDLPort);

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(result.Item2);

                    File.WriteAllText(axcFile, Regex.Replace(File.ReadAllText(axcFile), @"<\?xml.*\</configuration\>", xmlDoc.InnerXml));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error encountered: {0}", e.Message);
            }

            return;
        }
    }
}

1 comment:

  1. Por primera vez, disfruté mucho jugando a las apuestas y a los casinos. Empecé a jugar en el sitio, lo que me dio grandes bonificaciones para empezar a jugar. Siempre te betsafe descargar en Argentina para apuestas deportivas dirán cómo dar los primeros pasos en el juego para obtener una gran bonificación.

    ReplyDelete