OData Connected Service in Visual Studio 2017

Leave a comment

Here we will use the OData Connected Service to connect to an OData feed from Visual Studio 2017.

First, install the extension. Select Tools->Extensions and Updates:

Select Online and search for OData Connected Service:

Restart Visual Studio to complete the install.

Create a new Visual Studio console app:

Right Click and select Add->Connected Service:

Select OData Connected Service:

Enter a service endpoint:

Select Settings and enter a name:

Click Finish.

The solution will now contain new files:

Getting Started opens the URL http://odata.github.io/odata.net/

The ConnectedService.json file has the endpoint URL:

Add the following code to the project to display products from the OData feed:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NorthwindModel;

namespace Carl.ODataTest
    class Program
        static void Main(string[] args)
            ODataWebExperimental.Northwind.Model.NorthwindEntities nw =
                        new ODataWebExperimental.Northwind.Model.NorthwindEntities(new Uri("http://services.odata.org/V4/Northwind/Northwind.svc/"));
            var products = nw.Products.ToList();
            foreach (var product in products)
                Console.WriteLine("Product Name: {0}", product.ProductName);

This will produce the following output:


Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

five − four =