Convert JSON to RSS via Web API? - c#

I would like to create a generic Web API action that will accept a JSON URL as a parameter, then convert it to RSS. Everywhere I look I find RSS to JSON but not the other way around.
I did not want to use a 3rd party service but instead looking for a library that can do this. Any idea on how to leverage Web API to do this or should I just create a simple HTTP Handler for this?

You could implementing your own RSS or Atom custom MediaTypeFormatter. You can implement it so that the request will use this formatter when the accept header is set to application/atom+xml or application/rss+xml.
Filip has a blog describing this:
RSS & Atom MediaTypeFormatter for ASP.NET WebAPI

Superfeedr provide a feed API which does RSS to JSON conversion both when you poll feeds and when you want to be notified for changes in them.

Related

Using protofub for ASP.NET Web API requests

I am working on a bunch of Web APIs which must have a latency of a single digit millisecond! To produce the response I am using protobuf which is great. My question is that can protobuf be used to de-serialize the request as well?
For example for such an API:
public async Task<List<Artist>> Search(SearchArtistRequest request)
I will write a SDK (a bunch of .DLL) which will make the call to this API and third parties will only use the .DLL. So if I could send my request message in protobuf format and de-serialize 'request' using protobuf then I might gain some performance improvements (given that by default Json.NET is used and its performance is aweful). Is there a way to do so?
You can create your own serializer, test it and replace existing one with yours in WebAPI.
There are a couple of resources about custom serialization in WebAPI.
Look here ("Testing Object Serialization"), Media Formatters and Replace...serializer.

Parsing Data in Xamarin Forms

I would like to get the names in collection href(CustomerDemographics, Customers, Employees, Order Details) to populate a listview. I would like to know how to parse these information in Xamarin platform or C#.
I am quite new on this environment. I have experience how to parse json data in native ios with objective c, but it is the first time I see this type of data.
From the attached image it seems that you're requesting the service document of the OData service. Namely the http://host/service/ endpoint of the service. If you would like to get the content of the collections, you should append the names of the collections to the end of the service document URL, such as:
GET http://host/service/Categories
GET http://hsot/service/CustomerDemographics
The format of the response payload depends on the protocol version of the OData service. If you are talking to a OData V4 service (it actually seems a lot like you are querying the Northwind OData V4 sample service: http://services.odata.org/v4/northwind/northwind.svc/), the response payload will be in JSON format and you can use the ways that you are familiar with to parse the response.
In addition, I would recommend you go through the basic tutorial on OData.org so that you can get a better grasp of OData requests: http://www.odata.org/getting-started/basic-tutorial/

how to build json object using .net and out it in http request

I'm building a mobile application that recive data from a server as json object , im using asp.net / sql server database to build the server , i dont know how to retrive data from sql database and convert it to json object that the client can request
I'm not using asp.net MVC
any help to start !
Check out JSON.net. It is a JSON serialization framework that has also been adopted by ASP.NET MVC Web API. You can install it via NuGet.
You can use JavaScriptSerializer class, for example:
SomeType obj = ....
JavaScriptSerializer serializer = new JavaScriptSerializer();
string json = serializer.Serialize(obj);
Then you should instruct browser to download json, here you can see:
Returning JSON object from an ASP.NET page
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.Write(json);
Response.End();
You can use other serializers too:
http://habrahabr.ru/post/133778/
If you're using ASP.NET MVC you can create a controller that returns JSON. In your controller do:
return Json(yourObject);
You can also do it using the Web API. It will do content negotiation for you and return the data in the format you request it (JSON, XML, etc.).
Web API reference: Getting Started with ASP.NET Web API 2
You need to build some sort of web service that handles this request.
Here's a couple of options.
You could use Web API to write the service and use its automatic serialization / deserialization helpers
You could also write up a class that implements IHttpHandler, parse the incoming request using a JSON deserializer library, and serialize a JSON response using the same serializer library. This might be simpler than using Web API, especially if you need to deal with query string parameters in a way that is odd when using the automatic parameter functionality in Web API.
There is also a way to do this using WCF, although it's even more complicated than the above.

How can I consume odata using json with c#?

I'm consuming an odata v2 api with c# / winRT. It works fine, but it's using xml as encoding format for both read and write requests. How can I make it use json instead?
I've already tried attaching an event handler to myDataSource.SendingRequest, and adding an "Accept" header, but the client-side library explicitly intercepts this and throws an exception. Also, I could not find any "Accept" property on the client side.
Thanks,
Adrian
Assuming you're using the WCF Data Services client library (as per Phani's blog post), then this is currently not possible. The client library doesn't support JSON (yet).
If you really need to consume JSON you would need to use the ODataLib directly, which is not as "easy to use" as the WCF Data Services client, but it gives you more flexibility as well. ODataLib is the reader and writer for OData wire format. See this blog post for a sample. The ODataLib for Metro itself - Microsoft.Data.OData.Metro should already be part of the VS 2012 RC release.
You need to add an accept header to the request: 'accept: application/json'

Can you view the XML generated by .NET when using a JavaWS service?

How can I view the XML being sent to a Java Web Service from a C#-based ASP.NET page?
I've created a disco object web ref in .NET from my Java WSDL, but when I use the likes of Fiddler to view the XML attached to the HTTP request, instead I see the form parameters being passed. Is there a way I can view the serialized XML?
Use tcpmon, from Apache, which can intercept traffic and redirect it to another host/port.
You set up a listener on port A, and all traffic is forwarded to host/port B.
At a minimum, you can view at the HTTP request and response with a packet sniffer like Ethereal/Wireshark.
Or you can use the XmlSerializer and serialize the object instance you are about to pass, to the disk, for instance.
Just a thought. I am certain this is not the best way to do it, but i guess it will work. The idea is to inject a respone filter and overide the write method to log all the output generated from the ASP.NET page.
To see how to program an ASP.NET filter check this article :
http://www.highoncoding.com/Articles/468_Protecting_Email_Addresses_Using_Response_Filters.aspx

Categories

Resources