Use Web API and OData controllers together

Important

This content is archived and is not being updated. For the latest documentation, see Microsoft Dynamics 365 product documentation. For the latest release plans, see Dynamics 365 and Microsoft Power Platform release plans.

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.

Create a Web API Controller

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

Note

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;

    [ComVisible(false)]
    [ExtendedController("Values")]
    [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.

See also

Retail Modern Point of Sale