B1

Hello!

Integrating Microsoft Dynamics AX with other applications can be challenging task especially if its with non-Microsoft platforms like PHP, Java, cURL, etc. It adds more complexity if the access is needed over the internet while using Windows authentication.

In this blog post, I would like to share how I successfully integrated Microsoft Dynamics AX 2012 with PHP application using cURL over the internet using NTLM. This integration is direct and there is no wrapper service in between. You can also use the cURL commands directly from the command line tool. This blog assumes that you are familiar with AIF and services, Dynamics AX 2012 development, some PHP and cURL. The development of AIF service is also beyond the scope and it is assumed that we already have AIF services ready for consumption. I will be demonstrating this for both Custom and Document AIF services.

Services used for this demo

1. Customer document service

2. Custom AIF service for item details

I will be sharing the challenges I faced and their resolutions.

1. Create an Inbound HTTP port 

Go to System administration/Setup/Services and Application Integration Framework/Inbound ports

Create a new port and select

Services operations – Customer create

Adapter : HTTP

Now you have to do 2 things:

a. Add service routing behavior

b. Set security to NTLM

a. Add service routing behavior

Our inbound port is ready but not yet deployed. Click Configure to open WCF settings.

B1

Now add service routing behavior. This step is mandatory. It will expose your IP address in the WSDL instead of the machine name. I wasted a couple of hours getting errors that the system is unreachable. You cannot use your machine name in the WSDL. It will work within the network but outside the network you should use your static IP addresss. This is where you do that:

 

B2

 

b. Set security to NTLM

To use secure transport communication, you should not use basic authentication. Also, Windows will not work with Php and cURL. Instead, use NTLM. This needs to be done at 2 place, once in your inbound port and next in your IIS authentication settings.

To set NTLM for inbound port, go to the WCF configuration and make the changes below:

 

NTLM

 

Deploy the inbound port. We are done with AX level settings.

Make similar changes in your IIS authentication for that service endpoint:

test

Now the configurations are done. Now, we’ll call this service using cURL and PHP.

Create a customer using AX 2012 Customer Document service:

1. First create a request xml for Customer create. It should look like the following:

Customer XML

 

cURL to create customer

Save the above xml file and call it CustR.xml

Next, open cURL and execute the script below:

curl.exe –ntlm –user domain\userName:password  http://192.130.13.12:8201/MicrosoftDynamicsAXAif60/AXPCustomerCreate/xppservice.svc  -H “Content-type: text/xml; charset=utf-8” -H “SOAPAction: http://schemas.microsoft.com/dynamics/2008/01/services/CustomerService/create” –trace-ascii dump.txt –data-binary @CustR.xml –v

Parameter name Purpose
user add credentials here with the format domain\user:password
data-binary specify the file name where your data is. In our case, it was the request xml
SoapAction Mention the service action here.
H Its for specifiying the message headers. Details like Content-type, SoapAction, etc should come here.
NTLM This is the authentication we are using. It can be basic, negotiate or anyauth

Now, lets execute this using cURL. Boom! my customer got successfully created here. Here is the response:

customer creaet

Now, let me convert this code into Php. My script becomes the following:

PHP_CustomerCreate

For Custom AIF services:

Likewise, for Custom services you need to follow the same steps. AX does not expose the schema for a custom service so that becomes a pain point. Here is a sample working xml message:

<Envelope xmlns=”http://schemas.xmlsoap.org/soap/envelope/”>

<Header>
<CallContext xmlns=”http://schemas.microsoft.com/dynamics/2010/01/datacontracts”>
<Company>01</Company>
<Language>en-us</Language>
</CallContext>
</Header>
<Body>
<AXPulseCustomService xmlns=”http://tempuri.org”>
<_custAccount>1057</_custAccount>
<_itemId>00168138</_itemId>
<_qty>1</_qty>
</AXPulseCustomService>
</Body>
</Envelope>

That’s all folks. Thank you for reading. In case of confusion or any help, feel free to email me at Bilal@AXPulse.com

Leave a Reply

Recent Comments

    Archives

    Categories