How to request Http request and response in json - json

One major question is I can't simply use existed json library to put into my windows phone 7 applications.Is there any existed json library for wp7?
Another is how to request http and get response?

Try the Hammock Rest library on Codeplex alongside the excellent NewtonSoft JSON.NET library - also on codeplex.

Related

SignalR .Net Core 3.1 unable to send object in SendAsync method from service class

Previously I was using .Net Core 2.2, I was able to send a json object from a service class using hub context and SendAsync method to a front end web client. Im having issues after I've upgraded my project framework to 3.1. If i call the SendAsync method using a json object, it will hit an error stating "{"The collection type 'Newtonsoft.Json.Linq.JObject' is not supported."}", if I send any other class object it will directly go to OnDisconnected.
Sample of the method i use
Using Json Object: await _hubContext.Clients.Group(groupName).SendAsync("NotificationResponse", jsonObject);
Using Class Object: await _hubContext.Clients.Group(groupName).SendAsync("NotificationResponse", notificationObject);
I've tried sending object directly from the hub, I was able to send a normal class object but not a json object. I did the testing on my project and also sample from this tutorial: https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-3.1&tabs=visual-studio
I posted this question on github and got the answer from BrennanConroy. Thanks alot !
His answer was:
2.1 was using Newtonsoft internally for Json, 3.1 uses System.Text.Json. If you're using features that don't work with System.Text.Json you can switch back to Newtonsoft https://learn.microsoft.com/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#switch-to-newtonsoftjson
After doing this it fixed the issue.

ASP.Net MVC WEB API - JSON - auto add API version to generated JSON

I have developed an ASP.NET WEB API that generates JSON data to be consumed by some other party. Now I have received a request for adding some extra data in each JSON response about the version of the WEB API.
Is there a simple way to extend the built-in JSON formatter so it will auto-append/prepend some fixed JSON properties whenever it formats some data-model or a collection of some data-model?
Thanks for any good advice :-)

Netty 4 Pipeline for JSON over Websocket

I want to use Netty as a websocket server. On top I'd like to send JSON between the browser and the server for data interchange.
The websocket part works already fine (I'm using this code: https://github.com/raphaelstary/jsug-netty-example). Now I'd like to integrate a JSON Encoder/Deocoder into the pipeline. I found some code in the Netty Repo I would like to use (still beta, but I wanna try: https://github.com/netty/netty/commit/479b0fe43b6f9a06143cb39f09c51615df90fd1e)
Question: how do I use the Encoder/Decoder in the Pipeline in order to receive and send JSON Objects in my Handler?
Instead of using the JSON codec you mentioned, you could just send and receive a TextWebSocketFrame which contains the JSON string as its content and feed the JSON string into your favorite JSON library such as Jackson

How JSON POST request can be handled by WCF?

I need to handle, in my .net WCF service, JSON data (POST request) from a third party application.
Basically the third party app would be consuming my WCF service.
The posted JSON data structure is known.
I would like to know how the JSON data can be de-serialized in my service?
Create classes and attributes that copy the structure of json data and use this framework for serialization and deserilazation:
Json Framework
Classes can be generated here:
Json to classes

Consuming JSON WCF on Silverlight

I'm want to try changing a SOAP WCF to accept requests and return results in JSON format to make the data traffic less bulky.
I see that JSON requests functions looks like this:
wcfClient.OpenReadAsync(http://yourUrl.com/wcf/service1.svc/GetEmployees)
and do the regular SOAP requests functions instead that looks like :
wcfClient.GetEmployeesAsync();
1) For JSON results, do you need to parse them into an object or is it automatically parsed like SOAP?
2) Is there a way to do this without doing too much work like changing every single WCF calls in the project to looks "JSON-ish"?
To complement Davut's answer - WCF does support building RESTful services, although I agree that the ASP.NET Web API framework in general easier to use than WCF. JSON.NET is a great library, and it has nice deserialization capabilities (e.g., it can easily take the JSON which represent the list of Employee objects and convert them into the actual List<Employee> instance)
But for completeness sake, if you want to use a "normal" WCF client to access WCF-based services which return JSON, you can do it. It's not too straightforward, but you can do that by using a new encoder and behavior which does the conversion. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2010/04/29/consuming-rest-json-services-in-silverlight-4.aspx talks more about it, and has a pointer to a code sample.
In short, it's possible to consume JSON using a WCF client in Silverlight, but due to its complexity it's usually not done, and Davut's option (use a HTTP client such as WebClient to download JSON, then a library such as JSON.NET to parse it into objects) is preferred.
Firstly the idea "make the data traffic less bulky." is good.
Especially for Mobile devices. Beside this don't think that WCF xml causes network issues for PC. XM is the one of most compressible format. By WCF binary it goes as compressed.
For "Is there a way to do this without doing too much work?"
Yes there is a way name on it RESTFul Services(Restless Services). Now Microsoft directly support it by WEBApi.
Also you may use ODATA for filtering,ordering operations
Here are some links,
http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx
http://blogs.msdn.com/b/rjacobs/archive/2010/06/14/how-to-do-api-key-verification-for-rest-services-in-net-4.aspx
ODATA
http://www.odata.org/documentation/uri-conventions#FilterSystemQueryOption
A few practice notes,Some restrictions:
EntityFrameWork entities derived from EntityObject which has IsReferenceType attribute doesn't allow you to JSON serialize. ( I produced POCO objects using an automapper mapped them and serialized json)
WEBAPI support you much think such as WebGet,WebInvoke GetXML Give JSON ,ODATA features(just select and format not allowed.)
Note:In your web request's header you should accept text/json to get really json.
"For JSON results, do you need to parse them into an object or..."
I can say you should try JSON.NET it's portable library works everywhere. When you deserialize with a generic function it returns you the collection you expect.
Hope it helps someone. While discovering these stackoverflow helped me like an assistant.