Building clients for OData services
Finally, let's see how a .NET client might call the OData web service. Let's review how clients interact with an OData service.
If we want to query the OData service for products that start with the letters Cha
, then we would need to send a GET
request with a relative URL path similar to the following:
catalog/products/?$filter=startswith(ProductName, 'Cha')&$select=ProductId,ProductName,UnitPrice
OData returns data in a JSON document with a property named value
that contains the resulting products as an array, as shown in the following JSON document:
{
"@odata.context": "https://localhost:5101/catalog/$metadata#Products",
"value": [
{
"ProductId": 1,
"ProductName": "Chai",
"UnitPrice": 18
},
We will use our Northwind.Mvc
project as a client, and define a model class to make it easy to deserialize the HTTP response:
- In the...