Content Negotiation enabled endpoints rendering as XML in browsers

53 views
Skip to first unread message

Kevin Miller

unread,
Feb 8, 2012, 3:31:45 PM2/8/12
to fubumv...@googlegroups.com
Chrome and Firefox are sending this Accept header:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

After grabbing the latest Nuget my conneg enabled views are now
rendering as XML in the browser.

Side note: It looks like the XmlFormatter really hates IEnumerable<T>
in output models. I had to start returning arrays to prevent the XML
formatter from blowing up with a

Cannot serialize member Foo of type
System.Collections.Generic.IEnumerable`1[[FQTN]] because it is an
interface.

Jeremy D. Miller

unread,
Feb 8, 2012, 3:34:32 PM2/8/12
to fubumv...@googlegroups.com
So yes, it's a real problem to fix later/soon-ish, but how are you setting up conneg in your endpoints?  If you only enabled json on those endpoints the xml rendering would no longer be happening.
 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: Kevin Miller <scou...@gmail.com>
To: fubumv...@googlegroups.com
Sent: Wed, February 8, 2012 2:31:45 PM
Subject: [fubumvc] Content Negotiation enabled endpoints rendering as XML in browsers
--
You received this message because you are subscribed to the Google Groups "FubuMVC Development Group" group.
To post to this group, send email to fubumv...@googlegroups.com.
To unsubscribe from this group, send email to fubumvc-devel+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fubumvc-devel?hl=en.

Jeremy D. Miller

unread,
Feb 8, 2012, 3:49:18 PM2/8/12
to fubumv...@googlegroups.com
That'll work too, but you could just do a convention that calls

graph.Behaviors.Where(x => x.InputType().CanBeCaseTo<IApi>() || et al.).Each(x => x.MakeAsymmetricJson());

That'll set up conneg support, but only with the Json formatter.
Sent: Wed, February 8, 2012 2:46:25 PM
Subject: Re: [fubumvc] Content Negotiation enabled endpoints rendering as XML in browsers

I apply content negotiation like this:

Media.ApplyContentNegotiationTo(x => x.InputType().CanBeCastTo<IApi>()
|| x.InputType().CanBeCastTo<IUnauthenticatedApi>());

So you are saying I can add a .Formatter<JsonFormatter>(); and all is well?

Kevin Miller

unread,
Feb 8, 2012, 4:01:23 PM2/8/12
to fubumv...@googlegroups.com
Thanks,

Looks like adding Formatter<T> does not fix the problem. I applied
your MakeAsymmetricJson() to the appropriate behaviors with success to
get me going for now. Of course down the road we may have customers
crazy enough to want XML.

On Wed, Feb 8, 2012 at 2:49 PM, Jeremy D. Miller

>> fubumvc-deve...@googlegroups.com.


>> For more options, visit this group at
>> http://groups.google.com/group/fubumvc-devel?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "FubuMVC Development Group" group.
>> To post to this group, send email to fubumv...@googlegroups.com.
>> To unsubscribe from this group, send email to

>> fubumvc-deve...@googlegroups.com.


>> For more options, visit this group at
>> http://groups.google.com/group/fubumvc-devel?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "FubuMVC Development Group" group.
> To post to this group, send email to fubumv...@googlegroups.com.
> To unsubscribe from this group, send email to

> fubumvc-deve...@googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/group/fubumvc-devel?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "FubuMVC Development Group" group.
> To post to this group, send email to fubumv...@googlegroups.com.
> To unsubscribe from this group, send email to

> fubumvc-deve...@googlegroups.com.

Kevin Miller

unread,
Feb 8, 2012, 4:04:23 PM2/8/12
to fubumv...@googlegroups.com
Jeremy, would you like me to create an issue for this on GitHub?

Jeremy D. Miller

unread,
Feb 8, 2012, 4:06:19 PM2/8/12
to fubumv...@googlegroups.com
Can you just add a comment to the existing issue on conneg?  I think it's 215.

I *think* that just pulling the view rendering into conneg will solve this stuff permanently, but I just don't wanna tackle it right now.
 
Sent: Wed, February 8, 2012 3:04:23 PM
>>> fubumvc-devel+unsub...@googlegroups.com.

>>> For more options, visit this group at
>>> http://groups.google.com/group/fubumvc-devel?hl=en.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "FubuMVC Development Group" group.
>>> To post to this group, send email to fubumv...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> fubumvc-devel+unsub...@googlegroups.com.

>>> For more options, visit this group at
>>> http://groups.google.com/group/fubumvc-devel?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "FubuMVC Development Group" group.
>> To post to this group, send email to fubumv...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> fubumvc-devel+unsub...@googlegroups.com.

>> For more options, visit this group at
>> http://groups.google.com/group/fubumvc-devel?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "FubuMVC Development Group" group.
>> To post to this group, send email to fubumv...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> fubumvc-devel+unsub...@googlegroups.com.

>> For more options, visit this group at
>> http://groups.google.com/group/fubumvc-devel?hl=en.

--
You received this message because you are subscribed to the Google Groups "FubuMVC Development Group" group.
To post to this group, send email to fubumv...@googlegroups.com.
To unsubscribe from this group, send email to fubumvc-devel+unsub...@googlegroups.com.

Kevin Miller

unread,
Feb 8, 2012, 3:46:25 PM2/8/12
to fubumv...@googlegroups.com
I apply content negotiation like this:

Media.ApplyContentNegotiationTo(x => x.InputType().CanBeCastTo<IApi>()
|| x.InputType().CanBeCastTo<IUnauthenticatedApi>());

So you are saying I can add a .Formatter<JsonFormatter>(); and all is well?

On Wed, Feb 8, 2012 at 2:34 PM, Jeremy D. Miller
<jeremy...@yahoo.com> wrote:

> fubumvc-deve...@googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/group/fubumvc-devel?hl=en.
>

> --
> You received this message because you are subscribed to the Google Groups
> "FubuMVC Development Group" group.
> To post to this group, send email to fubumv...@googlegroups.com.
> To unsubscribe from this group, send email to

> fubumvc-deve...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages