OData Connected Service in Visual Studio 2017

5 Comments

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:

We will connect to:  https://services.odata.org/V4/Northwind/Northwind.svc/. The service looks like:

Enter the service endpoint and name and click Next:

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);
            }
            Console.ReadLine();
        }
    }
}

This will produce the following output:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

5 Responses to OData Connected Service in Visual Studio 2017

Leave a Reply

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