Question

I've got an interesting situation. I have two applications calling a function on a Microsoft WCF OData service:

  1. Android using OData4J library (v0.7)
  2. iOS using OData4ObjC library (Elizabeth Duncan fork for iOS 6.1)

The OData service is written using Microsoft WCF Data Service v5.6. I'm using a [WebGetAttribute()] attribute on a method in my service class:

namespace MyServices
{
    public class MyService : DataService<MyEntities>
    {
        public static void InitializeService(DataServiceConfiguration config)
            {
                config.UseVerboseErrors = true;
                config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
                config.SetServiceOperationAccessRule("MyServiceCall", ServiceOperationRights.ReadSingle);
            }

        [WebGet()]
        public IQueryable<MyComplexType> MyServiceCall()
        {
            return AListOfMyComplexTypes();
        }
    }
}

When the Android app makes an OData function call, the WCF data service responds with a v1 collection of complex types. When the iOS library makes a function call to the WCF data service it is expecting the collection to be returned using v3.

My questions are:

  1. Is it possible to get the OData4ObjC library to communicate using OData v1 protocols?
  2. Is it possible to get the WCF Data Service to respond using OData v3 protocols?
  3. What do I need to do to get item 1 and/or item 2 to work?


Here's what I mean by an OData v1 response:

<MyServiceCall
    xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <element m:type="MyService">
        <Id m:type="Edm.Int16">1</Id>
        <Name>Bariatric</Name>
        <IsEnabled m:type="Edm.Boolean">true</IsEnabled>
    </element>
    <element m:type="MyService">
        <Id m:type="Edm.Int16">2</Id>
        <Name>General</Name>
        <IsEnabled m:type="Edm.Boolean">true</IsEnabled>
    </element>
</MyServiceCall>

And this is what I mean by an OData v3 response:

<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://services.odata.org/V3/(S(ii5qwgb20wk0ptgfvvtlpwoy))/OData/OData.svc/" 
    xmlns="http://www.w3.org/2005/Atom" 
    xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"         
    xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>
http://services.odata.org/V3/(S(ii5qwgb20wk0ptgfvvtlpwoy))/OData/OData.svc/GetProductsByRating</id>
<title type="text">GetProductsByRating</title>
<updated>2013-10-17T21:56:42Z</updated>
<link rel="self" title="GetProductsByRating" href="GetProductsByRating" />
<entry>
<id>http://services.odata.org/V3/(S(ii5qwgb20wk0ptgfvvtlpwoy))/OData/OData.svc/Products(1)/id>
    <category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link rel="edit" title="Product" href="Products(1)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category" type="application/atom+xml;type=entry" title="Category" href="Products(1)/Category" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier" type="application/atom+xml;type=entry" title="Supplier" href="Products(1)/Supplier" />
    <title type="text">Milk</title>
    <summary type="text">Low fat milk</summary>
    <updated>2013-10-17T21:56:42Z</updated>
    <author>
        <name />
    </author>
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Category" type="application/xml" title="Category" href="Products(1)/$links/Category" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml" title="Supplier" href="Products(1)/$links/Supplier" />
    <m:action metadata="http://services.odata.org/V3/(S(ii5qwgb20wk0ptgfvvtlpwoy))/OData/OData.svc/$metadata#DemoService.Discount" title="Discount" target="http://services.odata.org/V3/(S(ii5qwgb20wk0ptgfvvtlpwoy))/OData/OData.svc/Products(1)/Discount" />
        <content type="application/xml">
            <m:properties>
                <d:ID m:type="Edm.Int32">1</d:ID>
                <d:ReleaseDate m:type="Edm.DateTime">1995-10-01T00:00:00</d:ReleaseDate>
                <d:DiscontinuedDate m:null="true" />
                <d:Rating m:type="Edm.Int32">3</d:Rating>
                <d:Price m:type="Edm.Decimal">3.5</d:Price>
            </m:properties>
        </content>
    </entry>
</feed>
Was it helpful?

Solution

Maybe I'm misunderstanding your scenario, but from the examples you've posted here, I don't think this has anything to do with versioning. The call to MyServiceCall is a returning a collection of complex values, whereas the call to GetProductsByRating is returning a collection of entities. Since Atom doesn't have a concept of "a collection of complex values", OData defines its own XML format. But Atom does define a concept of "a collection of entities", so OData reuses the feed concept from Atom.

So I don't see an issue with versioning here. This is just a difference between the way that different kinds of payloads are formatted.

If you're looking at the HTTP headers, and you're confused about why a v3 server would ever respond with a header indicating the payload is v1, note that the WCF Data Services server always responds with the lowest version needed for that particular response. So if you ask a v3-capable server for a payload that has no v3 features, the server will mark the payload as being v2 or v1 (otherwise, it might block clients that are not v3 compatible but would actually be able to read this payload).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top