0
votes

I am quite new to oData webservices. I would like to get and populate the following output on mobile platform. I could able populate the following url data on mobile platform http://services.odata.org/V4/Northwind/Northwind.svc/Customers . However, once I started on doing another exercise. I am stuck with the following odata output. How could I access to properties, such as Name or Description?

PUT /OData/OData.svc/Products(1) HTTP/1.1 Host: services.odata.org DataServiceVersion:
  1.0 MaxDataServiceVersion: 2.0 accept: application/atom+xml 
  content-type: application/atom+xml Content-Length: 1181 
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Entry xml:base="http://services.odata.org/OData/OData.svc/" 
    xmlns:d=" http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:m=" http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
    xmlns="http://www.w3.org/2005/Atom"> 
  <id>http://services.odata.org/OData/OData.svc/Products(1)</id>
  <title type="text"></title> 
  <updated>2010-02-28T10:23:02Z</updated>
  <author> 
    <name /> 
  </author> 
  <Link rel="edit" title="Product" href="Products(1)" /> 
  <category term="DataServiceProviderDemo.Product" 
      scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
  <content type="application/xml"> 
    <m:properties> 
      <d:ID m:type="Edm.Int32">1</d:ID>
      <d:Name>Milk</d:Name> 
      <d:Description>Low fat milk</d:Description>
      <d:ReleaseDate m:type="Edm.DateTime">1995-10-21T00:00:00</d:ReleaseDate>
      <d:DiscontinuedDate m:type="Edm.DateTime" m:null="true" /> 
      <d:Rating m:type="Edm.Int32">4</d:Rating>
      <d:Price m:type="Edm.Decimal">4.5</d:Price> 
    </m:properties> 
  </content>
</Entry>
1
Is your problem that you would like to update an entity in services.odata.org/v4/odata/odata.svc/ with the atom payload and get error? What's about accessing properties? Seems like a different question. Could you elaborate more on your scenario and the problem you met? :)Yi Ding - MSFT
I would like to get ID, Name, Description, ReleaseDate, Discontunie, Rating, Price property.casillas
The reason I was confused is that the HTTP verb is "PUT" in the output you attached. OK, now I think I know how to answer :)Yi Ding - MSFT
please go ahead, sorry for confusing Yi Ding :-)casillas

1 Answers

2
votes

There are several ways to access specific properties, as there are two kinds of properties on a entity: a non-navigation property and a navigation property.

A non-navigation property is either a primitive type property, a collection of primitive type property, a complex type property, a complex type property, or a stream property. When you query the entity set or a specific entity, the values of the non-navigation properties are by default inline of the entity payload:

e.g. ID, Name, Description, etc. are inline when you query:

GET http://services.odata.org/v4/odata/odata.svc/Products

If you want to choose the properties you need, you can use the $select query option. E.g.

GET http://services.odata.org/v4/odata/odata.svc/Products?$select=ID,Name

By appending such query option, you will find only the properties you need inline of the payload.

If you want to only access the property value, you should append the property name as a segment to the request URL to a single entity. E.g.

GET http://services.odata.org/v4/odata/odata.svc/Products(1)/ID

There is another kind of property: the navigation properties. They are either an entity type property or a collection of entity type property. Navigation properties describes the relationship between the different entities in the service. An example is the Categories navigation property on the Product entity.

Navigation properties are by default not shown inline of the entity payload. In order to include them inline, the $expand query option needs to be used:

GET http://services.odata.org/v4/odata/odata.svc/Products?$expand=Categories

If you want to only access the navigation property, the request URL is similar as it is for non-navigation properties:

GET http://services.odata.org/v4/odata/odata.svc/Products(1)/Categories

To learn more about how to issue different OData requests for different scenarios and what the URL conventions is, the following materials are helpful:

The tutorials on OData.org: http://www.odata.org/getting-started/basic-tutorial/ (basic), http://www.odata.org/getting-started/advanced-tutorial/ (advanced).

The URL convention spec of OData V4: http://docs.oasis-open.org/odata/odata/v4.0/os/part2-url-conventions/odata-v4.0-os-part2-url-conventions.html

The protocol spec of OData V4: http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html