Any C# Developer to guide me


#1

Hi,
I am from C# programming background, though i have good knowledge on web services and REST APIs, I am very new to this Open data standards, especially i couldnt get ‘protobuf’.

Is there any C# developer who can guide me with sample line of codes to consume real-time Datasets/APIs?

Thanks very much.
Muthu


#2

Hi @Muthu, please make sure to read all the information we have on our website for developers:
https://opendata.transport.nsw.gov.au/developers

Unfortunately we don’t offer coding guidance or assistance but hopefully another developer in our community will help you out. Also make sure to search our forum as I’m sure there are old threads that could be helpful.

Thanks,
Alex


#3

Hi Alex,
Thanks for your kind info. I have looked at that link.

Thanks again,
Muthu


#4

I’m not a C# developer, but I can try to explain protobufs. Don’t think of it as an API, think of it as an SDK. You provide a specification (like GTFS-realtime) to protoc (the protobuf compiler) and it outputs a bunch of C# classes you can use to read a feed in that specification.

So you need to:

  • Get a TfNSW-flavored GTFS-realtime proto file
  • Compile it to a C# library
  • Fetch the feed over HTTP
  • Use the library to read the data from the feed

Hope that helps!


#5

Hi Jayen,
Thanks for your kind info, much appreciated.

Cheers,
Muthu.


#6

I received this question, for which the answer may also help you:

Is there any way to download GTFS-R (real time data) for all services (Bus/Train/Ferri) for all locations, because there is a limitations of max 60,000 calls to TfNSW API per day. If this real time data is available in our DB we can easily provide info to our customers.

GTFS-realtime is not an API, but a data format. GTFS-realtime is intended for getting the whole city at once. TfNSW has broken it up into one “download” for each mode (two for trains). One API call should get you all services for all locations for one mode.


#7

Great.
Getting some clear picture now.
Can you please point out the realtime data API endpoints (you mentioned 2 for trains).
So the data downloaded will be in GTFS-R format and we need to parse and push into DB for our usage?
Then i need to find a C# formatter or converter.

Thanks Jayen.


#8

I believe this is the one you want: https://opendata.transport.nsw.gov.au/dataset/public-transport-realtime-trip-update

There are two more APIs (one for vehicle positions and one for alerts).

The data downloaded will be in GTFS-realtime format and you need to parse and push into your DB for your usage.

You need to compile a C# reader as I said in Any C# Developer to guide me . It is unlikely you will find one. Also, I forgot to mention the protoc compiler minor version (e.g. 3.6) must match the protocol buffer library minor version. (The C# library you create may have a dependency on the protocol buffer library.)


#9

Thanks a lot Jayen.
Very much appreciated.


#10

Hi Jayen,

How to get the TfNSW-flavored GTFS-realtime proto file from https://opendata.transport.nsw.gov.au/node/330/exploreapi#!/ferries/GetFerries endpoint?

Thanks,
Muhammad Masood


#11

the .proto file isn’t part of the endpoint, but you need it to parse the endpoint. i don’t think ferries are different from the standard GTFS-realtime proto, but the TfNSW-flavored ones are here: https://opendata.transport.nsw.gov.au/troubleshooting


#12

Thanks Jayen.

I tried to generate c# code using protoc but getting error that “C# code generation only supports proto 3 syntax”. How can I generate C# classes using protoc for proto file?

Thanks,
Muhammad Masood


#13

Hi Jayen,

I found https://github.com/briansrepo/gtfs-realtime-proto3 which is basically version 3 of proto and I can use it to generate classes.

Am I on right track?

Thanks,
Muhammad Masood


#14

Hi,

I am just updating so that anyone who wants to consume ferrie data in C#. I followed https://github.com/google/gtfs-realtime-bindings/tree/master/dotnet and I can parse data successfully.

Thanks @jayen for all your help.

Thanks,
Muhammad Masood


#15

That all sounds right, but the google one looks like it was last updated four years ago, and the briansrepo one looks like it was last updated two years ago. So while it’ll mostly work, you may have trouble to get any new fields that were recently added to the GTFS-realtime specification, and also the TfNSW extensions.


#16

Hi Jayen,

When using proto3 to generate classes and parsing it, I was getting invalid Wire Type error. But using Nuget package mentioned https://github.com/google/gtfs-realtime-bindings/tree/master/dotnet I don’t need to generate any classes, it has all the classes and I used to get the data.

Thanks a lot @jayen again.

Thanks,
Muhammad Masood


#17

pretty sure you won’t get carriage occupancy for the trains, or which buses are christmas buses.

depending on the version of GTFS-realtime they used to create the bindings, you may also not get the train transpositions.


#18

Thanks @jayen for your reply. Where I can see the full format of the data (data structure with hierarchy etc) is returned by ferries api?

Thanks,
Muhammad Masood


#19

@alejandro.felman do you know which proto file corresponds to the ferries API? is it the latest standard GTFS-realtime with no TfNSW extensions?