Creating an HTTP Service with Web API: Listing 2

RegisterRoutes() modified for using built-in test client.

    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

        Dim config = New HttpConfiguration() With {.EnableTestClient = True}

        'routes.Add must be addded prior to the routes.MapRoute() because the Inventory API does not correspond to
 a controller+action combination.
        routes.Add(New ServiceRoute("InventoryWebAPIs/Inventory", New HttpServiceHostFactory() With {.Configuration =
 config}, GetType(InventoryAPI)))

        ' MapRoute takes the following parameters, in order:
        ' (1) Route name
        ' (2) URL with parameters
        ' (3) Parameter defaults
        routes.MapRoute( _
            "Default", _
            "{controller}/{action}/{id}", _
            New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
        )

    End Sub

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