Use Web API and OData controllers together [AX 2012]

Updated: April 29, 2014

Applies To: Microsoft Dynamics AX 2012 R3

By default, all the Retail Server binaries in Microsoft Dynamics AX use OData only. If you want to use a controller that uses a traditional Web API, you can create your own Web API controller and extend the Web API configuration.

The following example demonstrates how to create a Web API controller for Retail Server.


You can find the sample code from this topic in the Retail SDK.

namespace Microsoft.Dynamics.RetailServer.Samples.Extensions
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using System.Web.Http;
    using Commerce.Runtime.DataModel;
    using Retail.StoreServerServiceLibrary;

    [CommerceAuthorization(AllowedRetailRoles = new string[] { CommerceRoles.Anonymous }, CheckRetailOperation = false)]
    public class ValuesController : ApiController
        // GET /api/values
        public IEnumerable<string> Get()
            return new string[] { "value1", "value2" };

To create the controller, you need to create a new class that uses the Export attribute and specify that the type is the IWebApiConfig interface. The IWebApiConfig interface has one method you can override called Register. After you override the Register method, you can call the base class to get the same mapping as an OData metadata controller.

You must derive from the standard web API controller, and then you can customize the controller to meet your business needs. For more information, see ASP.NET Web API.

Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).