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

  • VS Code Java Team Improves 'Getting Started' Experience

    Microsoft's dev team responsible for the Java on Visual Studio Code extensions released a new update that eases the "getting started" experience, addressing feedback from new users who want an easier onramp.

  • Data Prep for Machine Learning: Encoding

    Dr. James McCaffrey of Microsoft Research uses a full code program and screenshots to explain how to programmatically encode categorical data for use with a machine learning prediction model such as a neural network classification or regression system.

  • Surface Duo Debut Presents Dual-Screen Dev Challenges

    Microsoft officially launched its new dual-screen Android device, Surface Duo, presenting new challenges -- and opportunities -- for developers to leverage the new form factor.

  • What's New in Blazor Tooling Updates

    Here's a quick look at what four major third-party Blazor tooling vendors have offered lately for Microsoft's red-hot project that allows for web development with C# instead of JavaScript.

  • Xamarin.Forms 4.8 Ships with Experimental Drag & Drop, Gradients/Brushes

    Microsoft shipped Xamarin.Forms 4.8 with two new experimental features leading the improvements to the C#-based cross-platform UI toolkit: gradients/brushes for "painting" in an app and drag-and-drop functionality within an app.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events