AIF

Validate AIF ports if they are running in AX

It may happen that AIF ports are failing due to an error, or they do not activate when the AX AOS instance gets started. There is a way to validate AIF ports if they are running correctly using a combination of X++ code and a PowerShell script that you may find below.

Add the following to the Global class collection and do a Full CIL:

public static client boolean WIK_notStartedAIFPortExists()
{
    #Aif
    AifInboundPort  port;
    Map             serviceStatusMap;
    str             serviceTypeName, status;

    boolean ret             = false;
    boolean isPortStarted   = false;

    serviceStatusMap = appl.getServiceHostStatus();


    if (serviceStatusMap)
    {
        while select Name from port
        {
            serviceTypeName = strFmt('%1.%2', #DotNetServiceNamespace, port.Name);

            if (serviceStatusMap.exists(serviceTypeName))
            {
                status            = serviceStatusMap.lookup(serviceTypeName);
                isPortStarted     = strStartsWith(status, #WcfCommunicationState_Opened);

                if (!isPortStarted)
                {
                    ret = true;
                    break;

                }
            }
        }
    }

    return ret;
}

And here is the PowerShell script to validate AIF ports. Please make sure you provide a comma-separated list for the AOS names, and a correct path where the Business Connector DLL could be found. Also you might want to provide credential details for the AX login if the user running the script does not have access.

# Set variables

$computerName = "TESTAOS01,TESTAOS02" -split ','
$AXBCpath = "C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"

# Validate Administrative privileges and Elevated command prompt

Write-Host "Validating security privileges... " -NoNewline

if (-NOT [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"))
{
    throw "You must be running the script in an Elevated command prompt using the Run as administrator option!"
}

if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
    throw "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"    
}

Write-Host "Done" -ForegroundColor Yellow

# Script for checking AIF

[ScriptBlock] $global:CheckAIFPorts =
{
    param ([string] $AXBCpath)
    try
    {
        $bcassembly = [Reflection.Assembly]::Loadfile($AXBCpath)      
        $ax = new-object Microsoft.Dynamics.BusinessConnectorNet.Axapta
        $ax.logon("","","","")
        $xSession = $ax.CreateAxaptaObject("XSession")   
        $AOSName = $xSession.call("AOSName")
        
        Write-Host -NoNewline "$AOSName AIF ports are ... "
        if ($ax.CallStaticClassMethod("Global", "WIK_notStartedAIFPortExists") -eq $false)
        #if ($ax.CallStaticClassMethod("Global", "isaos") -eq $true) #"WIK_notStartedAIFPortExists")
        {
            Write-Host "OK" -ForegroundColor Yellow
        }
        else
        {
            Write-Host "NOT OK" -ForegroundColor Red
        }
        $logedOff = $ax.logoff()
    }
    catch [Exception]
    {
	    Write-Host "Failed" -ForegroundColor Red
	    Write-Host $_.exception.message
    }
}

$Session = New-PSSession -ComputerName $computerName
Invoke-Command -Session $Session -ScriptBlock $CheckAIFPorts -ArgumentList "$AXBCpath"
Remove-PSSession -Session $Session

validate AIF ports

 

By |2016-08-17T09:02:35+02:00August 17th, 2016|Categories: AX 2012|Tags: , , , , |2 Comments

AIF port changes without deactivating

For troubleshooting the Application Integration Framework in AX sometimes we have to enable logging of all XML document messages. However the AIF inbound ports cannot be edited by default without deactivating them first. It is a common misbelief that you need to do this.

If you deactivate and reactivate a port, in the background it just regenerates the server-side WCF settings in table AIFWCFConfiguration, that stores the XML string in a container field. Most of the values in there does not actually relate to a lot of fields that you should be able to change. In our case the LoggingMode field was in the scSC parent table of AIFPort.

What we could do instead of deactivating and reactivating our service in question to switch the logging on and off was to simply edit the record in the table browser, which does in fact take immediate effect and the logging will commence or get suspended once you save the row. Please keep in mind that for other fields such as user restrictions or service operations you should do your own research in a Test environment first to decide if it is safe to go ahead with the modification.

By |2015-11-23T17:43:17+01:00October 15th, 2015|Categories: AX 2012|Tags: , , |0 Comments
Go to Top