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:
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
What is ODataWebExperimental.. Doesn’t seem to be a function available using the libraries you are using?
Hi, this should be generated in the Northwind.cs file under the ODataService folder. I have it as line 7402.
What if it is not generated in Northwind.cs file
because i don’t see that in my generated code
Any reason why it keeps telling me page returned unauthorized i even inluded webproxy and network credentials