Category Archives: WCF

The CustCustomerService (External name CustomerService) can be used to create a customer in Ax through AIF.
When using the http adapter and consuming this service in a .Net Application, this is a tried and tested way to do it.
Notice the DirPartyTable assignment in the code. You do not need to specify the DirParty member, but that is where the customer name is held in Ax 2012

Android SDK(2.3.3) (We arent useing any OS specific feature. This app should be able to be written in much lower versions)

Gson (Google Json library, this is a pretty lightweight and easy to use JSON library as compared to the one already included within the Java SDK)

So the first part of the process is to create the Android application. This should be some basic general settings

Make sure to have the “Create activity” set to true. That creates a default activity to start with the application.

Because we are going to access our web service (i.e. use the internet) we need to give that access to the app (otherwise this will lead to frustration and excessive drinking and may also lead to baldness). To do so, add the following line to the AndroidManifest.xml file within the <manifest> tag

<uses-permission android:name="android.permission.INTERNET"/>

We will now create the UI for this. This will be split into 2 UI elements. One which is the main page, and the second which defines each row of the Items to be displayed. I Will try to make the UI look as close to the one in Joris’s Blog.

The main UI: When the application is created, a UI xml file is already created under /res/layout/main.xml

Main Layout

Item row layout

This UI starts with a TextView (User name label), a TextViewEdit (Username), Button (Get items), followed by another label (this will fetch the application name from the web service)

Follows that is a ListView placeholder. Later on the list view will be set to use the secondary view which contains the definition of a Row

Here we are only showing the Item Id and Item name below the other and with a different height for the item

We now have to link the Item_row UI to the LIstView. This is done using Adapters. There are lots of examples online how to attach a Listview to a array of strings, but very few with array of some class.

What i will do is First Show the Main Activity (this is where the item_row gets attached to the ListView too)

In the Activity class “LooneyDroidActivity” we will declare our 3 UI elements we would want to access. (In Android, the Activity can be linked to any UI, and hence we need to fetch the elements ourselves, unlike Silverlight )

The “setContentView” sets the UI to be used by the activity. This is how the app knows which UI layout to show. you also see “R.id.*” R is a class auto generated and resides under /gen/package name/R. Every time UI element is created, the ID for it is generated and stored in the class.

in the Main.xml layout, you also see the button element has a onClick method. This needs to be manually defined inside the activity class.

The button click is doing 2 calls to the WCF service, to get the application name and then the item list.

For each call it goes to the RESTClient class, which returns the JSON string. The ProcessJson class converts that JSON to an object using the GSON library. The first process returns a string, the second an array of item (the item class consists of just the ItemId, and name).

I think this is already well beyond the 10 minute mark (took me more than that too)

The REST Client: (To call the WCF services, and fetch the JSON result)

And if you enter an incorrect username, you get the error. (this is just error handling, and no connectivity to the web service will also give the same error)

Android Ax Incorrect Login result

This Android app is just a basic Single Activity based app, with no menu items or additional activities. The trusted intermediate Works just as expected with this too. What I haven’t covered on this yet is securing the WCF services by SSL and then consuming it from Android. I haven’t ventured into that jungle yet, but will try to post one on that later.
This concludes the Android app for Ax. I don’t think this would be anywhere near 10 minutes (especially with the ListView and the Custom Adapter we had to create), but that all depends with your Android skills. There was a lot of joy once I got this working, hopefully there will be more integration into Ax coming soon 🙂

This is part 1 of 2 to explain the process of creating the Android application to connect to Ax via AIF services.

Unlike the blog mentioned above, I had to enable REST in the WCF service, and output it as JSON. This is because android has a better JSON support than SOAP (ksoap can be used to consume the WCF services, but I have found JSON to be a much easier approach)

To enable REST services, I installed the WCFRestContrib package. This is available from NuGet and can be installed using

PM> Install-Package wcfrestcontrib

We can create the WCF Service using the no configuration mode. This link defines how to create a WCF service with no configuration. Which means most of the web.config is deleted, and another identifier is attached to the SVC file. This however relies of transport security as there is no SOAP envelope around this. WCFRESTContrib allows to create a custom authentication system. The authentication data can be retrieved from the HTML headers and verified.

So the WCF service should look like this, it enables a GET method and has a certain URI, and outputs the data in JSON

Notice the header attributes. This needs to be defined and is based on the WCFRESTContrib package. The authentication classes created is. Notice that the Username and password are being sent in the header with the tag “Authorization” this can be renamed to anything you like

The aim is to start from a web service to consume an AIF service, and then move that to a file system adapter. I will that take that a step further by adding a .Net transformation library so that we can import a CSV file to do the same. All throughout the process, there will be no change done within Dynamics Ax itself.

The service I am going to consume throughout the series is the InventItemService , and i will create an item.

With AX2012, we need to create a product and then release it. So for this demonstration, I will assume that the Products have been created, but have not been released yet.The AIF webservice InventItemService.create will do this for us.

Create and Consume web service:

I have found consuming AIF as web services easier than File adapter, which is why I start with this and then move this over to the File adapter.

Setting the AIF HTTP port to expose the InventItemService.Create:

Add InventItemService.create to the port

Once the Inbound port is activated, we can consume this in Visual studio. I shall create a Console application, and hard code the items to be created.

In Visual studio, add the service reference using the URI field of the Inbound Port.