How to Consume OData Service in LightSwitch 2012

What is OData? OData is a standardized protocol for creating and consuming data APIs. OData builds on core protocols like HTTP and commonly accepted methodologies like REST. The result is a uniform way to expose full-featured data APIs. For more info read http://www.odata.org/.

Getting Started

  1. Open Visual Studio 2012.
  2. Go to "File" => "New" => "Project..."
  3. Select "LightSwitch" in installed templates.
  4. Select "LightSwitch Application (Visual C#)".
  5. Enter the Name and choose the location.
  6. Click "OK".

Now click on "Attach to external Data Source" and select ODataService and click the "Next" button.

img1.jpg
Image 1.

Now enter the connection information and specify the OData service endpoint and click the "Next" button.

img2.jpg
Image 2.

Right now I am using a default OData service.

<service xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app"xml:base="http://services.odata.org/OData/OData.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="Products">
<atom:title>Products</atom:title>
</collection>
<collection href="Categories">
<atom:title>Categories</atom:title>
</collection>
<collection href="Suppliers">
<atom:title>Suppliers</atom:title>
</collection>
</workspace>
</service>

Now choose your entities and click "Finish".

img3.jpg
Image 3.

This is the designer:

img4.jpg
Image 4.

Now add a screen and select a service name from the screen data.

img5.jpg
Image 5.

Now finally run the application to see the product list.

img6.jpg
Image 6.

Up Next
    Ebook Download
    View all
    Learn
    View all