4

The example services mean this: http://services.odata.org/V4/Northwind/Northwind.svc/

My question is:

  1. Why this service has a ".svc" suffix? As I know, now only two ways can implement odata v4 services on .Net platform, RESTier and WebAPI, see http://odata.github.io/, but both of them not have ".svc". In fact, wcf data services has ".svc", but wcfds not support odata v4.

  2. This example service's response body is high optimization, like this:

    HTTP/1.1 200 OK
    Cache-Control: private
    Content-Length: 2015
    Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
    Expires: Sat, 24 Oct 2015 05:10:34 GMT
    Vary: *
    Server: Microsoft-IIS/8.0
    X-Content-Type-Options: nosniff
    OData-Version: 4.0;
    X-AspNet-Version: 4.0.30319
    ...
    
    {"@odata.context":"http://services.odata.org/V4/Northwind/Northwind.svc/$metadata","value":[{"name":"Categories","kind":"EntitySet","url":"......
    

    just one line, like wcfds again, but my service like this:

    HTTP/1.1 200 OK
    Cache-Control: no-cache
    Pragma: no-cache
    Content-Type: application/json; odata.metadata=minimal; charset=utf-8
    Expires: -1
    Vary: Accept-Encoding
    Server: Microsoft-IIS/7.5
    OData-Version: 4.0
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Date: Sat, 24 Oct 2015 06:56:24 GMT
    Content-Length: 364
    
    {
      "@odata.context":"http://192.168.1.99:908/api/$metadata","value":[
        {
          "name":"Test","kind":"EntitySet","url":"Test"
        },{
          "name":"TDefStoreEmp","kind":"EntitySet","url":"TDefStoreEmp"
        },{
          "name":"TDefEmp","kind":"EntitySet","url":"TDefEmp"
        },{
          "name":"TDefStore","kind":"EntitySet","url":"TDefStore"
        }
      ]
    }
    

    too many lines, how did one line?

  3. So I suspect the example service is based on wcfds, but how it can support V4? in fact, i like wcfds, because it don't need any Controllers, i just want expose a database but don't want open 1433 port on the internet.

My english is not good, please understand and help me, thanks!

1 Answer 1

2
  1. You are right, this demo service is implemented using WCF Data Service. For web api based demo service, you can refer to :

http://services.odata.org/TripPinWebApiService

WCF Data Service for OData V4 is not officially supported, and it is recommended to use WebAPI instead.

  1. This is called indent for JSON, and it was enabled by default. To disable indent, please add the following to your webapi configuration code:

    var formatters = ODataMediaTypeFormatters.Create();

    foreach (var formatter in formatters) { formatter.MessageWriterSettings.Indent = false; }

    config.Formatters.InsertRange(0, formatters);

  2. The source WCF Data Service is public visible here: https://github.com/OData/odata.net/tree/WCFDSV4

Please note that the implementation indeed has some gap with OData V4 spec. But if you are interested, you can feel free to build it by yourself it or add new features.

As suggested, it's recommended to use WebAPI OData for setting up OData V4 service. Also, you could choose to use RESTier which resembles wcfds style more.

3
  • So that is it, i see, thank you very much for answer me! About the indent for JSON, i used your code in "WebApiConfig.cs", it work well for service's root url, for example: request xxx/api, then obtain a json body like "{"@odata.context":"xxx/api/$metadata","value":[{"name":"TAccStock..." in one line, but it not work on entity, request xxx/api/Emp?$top=10, return multi lines again. I'll try this WCFDSV4 lib. I tried RESTire, it is so simple to build a service, but there some problem let me disappointment, like datetime -> Edm.Date, lead to time data missing. Thank you.
    – ahdung
    Commented Oct 27, 2015 at 7:33
  • Excuse me, i have some curiousness, why did you know the official demo is based on wcfds? especially it's "not officially supported", are you the official internal guy^_^? just curiousness, you don't have respond to me. anyway, thank you again.
    – ahdung
    Commented Oct 27, 2015 at 7:53
  • 1.For wcfds, please refer to this blog post for detail: blogs.msdn.com/b/odatateam/archive/2014/03/27/… 2. For restier not working, looks like it is due to the following code(doing same thing but ignores the settings), maybe we can create a bug for this: github.com/OData/RESTier/blob/master/src/…
    – Karata
    Commented Oct 28, 2015 at 5:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.