« Seeking .NET Compact Framework support in Visual Studio 2010? | Main | Enabling PING (aka ICMP) on Windows Azure roles »

12/09/2010

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a012876b389bb970c0148c6903922970c

Listed below are links to weblogs that reference Using JSON.NET as a default serializer in WCF HTTP/Web/REST (vNext):

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Jasonsirota

I was actually just looking at this code path last night. I figured out how to add a JSON media type to the processors but I was having trouble with adding it as the default processor. Unless you pass the accept header, it still defaults to XML. Have you had that issue?

Christian Weyer

Hi,

you need to clean up first, like this:

public override void RegisterResponseProcessorsForOperation(HttpOperationDescription operation, IList processors, MediaTypeProcessorMode mode)
{
processors.ClearMediaTypeProcessors();

processors.Add(new JsonNetProcessor(operation, mode));
processors.Add(new BsonProcessor(operation, mode));
}

Glenn Block

Nice post Christian!

In the current bits, we take the first processor in the response pipeline as the default. You can use clear that processor collection in the RegisterResponseProcessorsForOperation method by calling the ClearMediaTypeProcessors on the processors param. Then just add back in Json first and it should work.

Black

It's a Very helpful article for me. Actually, I am fond of reading online punjabi news. Thanks for writing such a complete ..And,I wantn't to miss them.
Thank you for sharing..

Merlyn Morgan-Graham

I'm looking for a way to use Json.NET BSON that doesn't involve coding up a service framework, and doesn't encode the binary data as base64 (which is the best I've done so far). Something that streamed the data would be even better. This post looks perfect, but I also want to use this in production :)

You mentioned: "A more practical approach is to use Message or Stream as the response/request type and apply the serialization/deserialization inside the service façade operation implementation." Can you point me to some references, or basic classes I'd need to mess with to start along this path?

Ryan Riley

Excellent post! Would you mind if I added this into http://wcfhttpcontrib.codeplex.com/?

Cheers,
Ryan

Christian Weyer

Hi Ryan,

sure, go ahead! Just include the original reference, pls.

-Christian

Ryan Riley

Thanks! I just pushed it. Let me know if you would like me to add a copyright, etc. http://wcfhttpcontrib.codeplex.com/SourceControl/changeset/changes/768111a9a285

Ryan Riley

Btw, I noticed that WriteToStream didn't work. I worked with Glenn on it tonight and discovered that 1) the writer is closing the underlying stream before its use is completed (http://ydie22.blogspot.com/2008/02/about-idisposable-close-streams-and.html) and 2) the contents weren't flushed. Not sure if those are new issues with the latest bits, but I'm fixing them now. Should be up tomorrow.

rsf

will this approach honor [DataContract] / [DataMember] directives?

Dan

I am running my services through a windows service....where do I configure the custom host configuration?

thanks

The comments to this entry are closed.

Shared items (Google Reader)