4
votes

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!

2

2 Answers

2
votes
  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.

1
votes

If you are looking for TripPin OData sample you can find it here:

https://github.com/OData/ODataSamples/tree/master/Scenarios/TripPin