Creating an HTTP Service with Web API: Listing 3

Modified code for OData query.

Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports CarInventory.Inventory.Resources
Imports System.Linq  'Used for OData Support

Namespace Inventory.APIs

    <ServiceContract()>
    Public Class InventoryAPI

        <WebGet(UriTemplate:="")> _
        Public Function [Get]() As IQueryable(Of InventoryDTO)  'Using IQueryable allows for OData Support 
            'Public Function [Get]() As IEnumerable(Of InventoryDTO)
            Dim InventoryList = New List(Of InventoryDTO)() From { _
             New InventoryDTO() With {.Id = 1, .Year = 2012, .Make = "Cheverolet", .Model = "Corvette", .Color =
               "Red", .Quantity = 2},
             New InventoryDTO() With {.Id = 2, .Year = 2011, .Make = "Ford", .Model = "Mustang GT", .Color = 
               "Silver", .Quantity = 8},
             New InventoryDTO() With {.Id = 3, .Year = 2008, .Make = "Mercedes-Benz", .Model = "C300", .Color = 
               "Black", .Quantity = 5},
             New InventoryDTO() With {.Id = 4, .Year = 2010, .Make = "Dodge", .Model = "Charger", .Color = 
               "Blue", .Quantity = 7} _
            }
            Return InventoryList.AsQueryable   'Using AsQueryable allows for OData Support
        End Function

    End Class
End Namespace

About the Author

Sam Nasr has been a software developer since 1995, focusing mostly on Microsoft technologies. Having achieved multiple certifications from Microsoft (MCAD, MCTS(MOSS), and MCT), Sam develops, teaches, and tours the country to present various topics in .Net Framework. He is also actively involved with the Cleveland C#/VB.Net User Group, where he has been the group leader since 2003. In addition, he also started the Cleveland WPF Users Group in June 2009, and the Cleveland .Net Study Group in August 2009, and is the INETA mentor for Ohio. When not coding, Sam loves spending time with his family and friends or volunteering at his local church. He can be reached by email at [email protected].

comments powered by Disqus

Featured

Subscribe on YouTube