Any C# Developer to guide me

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

Hi @Muthu, please make sure to read all the information we have on our website for 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

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

Thanks again,
Muthu

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!

2 Likes

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

Cheers,
Muthu.

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.

2 Likes

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.

I believe this is the one you want: Public Transport - Realtime Trip Update | TfNSW Open Data Hub and Developer Portal

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 - #4 by jayen . 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.)

Thanks a lot Jayen.
Very much appreciated.

Hi Jayen,

How to get the TfNSW-flavored GTFS-realtime proto file from Explore API - Public Transport - Realtime Vehicle Positions API | TfNSW Open Data Hub and Developer Portal endpoint?

Thanks,
Muhammad Masood

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: Troubleshooting | TfNSW Open Data Hub and Developer Portal

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

Hi Jayen,

I found GitHub - brians-code/gtfs-realtime-proto3: A conversion of Google's realtime transit data format from proto2 to proto3 which is basically version 3 of proto and I can use it to generate classes.

Am I on right track?

Thanks,
Muhammad Masood

Hi,

I am just updating so that anyone who wants to consume ferrie data in C#. I followed gtfs-realtime-bindings/dotnet at master · MobilityData/gtfs-realtime-bindings · GitHub and I can parse data successfully.

Thanks @jayen for all your help.

Thanks,
Muhammad Masood

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.

Hi Jayen,

When using proto3 to generate classes and parsing it, I was getting invalid Wire Type error. But using Nuget package mentioned gtfs-realtime-bindings/dotnet at master · MobilityData/gtfs-realtime-bindings · GitHub 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

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.

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

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