Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 2.24 KB

use-web-api-and-odata-controllers-together.md

File metadata and controls

63 lines (41 loc) · 2.24 KB
title TOCTitle ms:assetid ms:mtpsurl ms:contentKeyID author ms.date mtps_version
Use Web API and OData controllers together
Use Web API and OData controllers together
1a8c2ac5-2eff-4e12-ab82-0dd7592d5b6d
62219715
tonyafehr
05/18/2015
v=AX.60

Use Web API and OData controllers together

[!INCLUDEarchive-banner]

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