I am using ASP.NET WebForms, which means I will be sending Protobuf data via ASPX or ASHX pages.
I am attempting to build a GTFSRT file, for which there is a Nuget package called GTFSRealTimeBindings. This uses Protobuf and Protobuf-net to compress and send the data.
The issue that I am having is that when the data is sent, something is getting jumbled, so it can't be read on the receiving end, and I am not sure how to correct it. I think it is in the encoding, but I am not setting that, so I am not sure how to change it.
What I ended up doing is writting an http handler (ashx page) that will download a GTFS file from another source, and then simply try to forward it. I know that the GTFS file can be read and de-coded from the other source. But every time I try to server the file from my ashx page, I can't decode the protbuf object.
Here is a very basic code set:
public class Vehicles : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
WebRequest req = HttpWebRequest.Create("https://cdn.mbta.com/realtime/VehiclePositions.pb");
FeedMessage feed = Serializer.Deserialize<FeedMessage>(req.GetResponse().GetResponseStream());
Serializer.Serialize(context.Response.OutputStream, feed);
}
}
In this snippet, you will note that I am downloading a Protobuf file from cdn.mbta.com, then simply trying to take the result that I got, and pass it back down.
When I try to read this into my sample application:
WebRequest req = HttpWebRequest.Create("http://localhost:54988/Secure/Admin/Reports/GtfsRt/Vehicles.ashx");
FeedMessage feed = Serializer.Deserialize<FeedMessage>(req.GetResponse().GetResponseStream());
The message I get is: 'Invalid wire-type; this usually means you have over-written a file without truncating or setting the length; see http://stackoverflow.com/q/2152978/23354'
If I run Fiddler while this page is hit, I notice that the response I get from cdn.mbta.com is different than the response that this page gives (minus the headers of course).
For example, the first two lines from mbta.com in fiddler show:
2.0 ] y1601"T
But the first two lines from my response are: 2.0 W y1601"N
Any ideas on what is causing this, and how I can correct it? I have tried setting the encoding using
content.Response.ContentEncoding=Encoding.Utf8
I and I went through and tried all of the other encodings to try to set it correctly.
======UPDATE====== In response to Marc's question, I have taken the Base64 string of the response payload, and the response from the first source does not match the response once I forward it on.
Response from mbta.com (limited to first few characters): Cg0KAzIuMBAAGI/e8eIFEl0KBXkwNzIzIlQKHAoIMzkyNTAwNjcqAjg4MAAaCDIwMTkwMjA3IABCDg
Response from my service (limited to first few characters): CgsKAzIuMBiP3vHiBRJXCgV5MDcyMyJOChgKCDM5MjUwMDY3GggyMDE5MDIwNyoCODgSFA3skilCFQ
As you can see, they are different. I will be working on a solution I can upload to demo the issue. Thank you again!