ASP.NET AJAX XML Serialization Format with LLBLGen Pro 2.5

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 21-Sep-2008 05:41:23   

Hi all,

My adapter entities are having issues being serialized by ASP.NET's JSON serializer. I read Fran's suggestion to enable XML serialization instead.

I enabled XML serialization using the ScriptMethod attribute, however, I noticed the XML being generated is Compact25 format.

The ASP.NET's AJAX javascript does not seem to deserialize the XML correctly ... and I get an XML document.

Is there a way to set LLBLGen to create Verbose XML, or more "standard" XML that might be properly parsed by ASP.NET AJAX?

Or am I misinterpreting how to get around the "circular reference issue" with JSON/LLBLGen?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Sep-2008 20:27:41   
  • LLBLGen Pro version?
  • Net Framework?
  • How are you sending and receiving entities (WS, WCF, ...)?
  • Did you read this already?
David Elizondo | LLBLGen Support Team
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 21-Sep-2008 21:11:30   

daelmo wrote:

  • LLBLGen Pro version?
  • Net Framework?
  • How are you sending and receiving entities (WS, WCF, ...)?
  • Did you read this already?

Yup, read that already.

LLBLGen Pro v2.5 Adapter Framework ASP.NET 3.5 with PageMethods

It seems when I use ScriptMethod(ResponseFormat:=XML) it outputs Compact25 XML. Is there a way I can control the output format?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Sep-2008 10:44:47   

Please check these links: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12057

And Josh Wright provides a sample here (check the attachement in his last pot): http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12426

And that's him blogging about it: http://www.readingwright.com/Post/Show/LLBLGen-to-JSon

mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 22-Sep-2008 14:26:59   

The blog entry looks very interesting... thank you!

GabeNodland avatar
Posts: 65
Joined: 31-Dec-2004
# Posted on: 28-Sep-2009 20:51:22   

I just found this thread while looking for a solution for this problem and wanted to add a solution I found in case someone else is searching for an answer too.

I am using .net 3.5 with VB I was was trying to return an entity from a webmethod in a web service, and was getting an error when it was trying to serialize to json.

I tried converting it to a json string and returning it, using System.Web.Script.Serialization.JavaScriptSerializer, which worked, but the client just got the json string as a string, and i wanted the results to be an object.

I would have tried Josh's stuff from his blog however i didn't want to convert all of his code to vb, it wasn't immediately clear to me how it worked since it returned a string, not sure if it would be Content-Type: application/json on the client side or just a string, like my other attempts. One of the comments on his blog from "NATHAN" pointed me to my solution.

So I changed my return type from Entity to Object and returned an anonymous type with just the fields i wanted.

I usually don't like anything that returns an Object but since it is only being called by JS i think this should be acceptable since it will be an object on the client side.



    <WebMethod()> _
    Public Function GetPortalItem(ByVal portalItemId As Integer) As Object
        Dim item = PortalItemManager.FetchByPortalItemID(portalItemId)

        'hack to return an anon type via json with just the data we want
        Return New With {.Title = item.Title, .PortalItemID = item.PortalItemId}

    End Function

I just let the magic of asp.net convert it for me to an object or actually a json string, and since it is doing the work it also knows to set the content type to json too. On the client side it is a javascript Object ready to use.

Gabe

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Sep-2009 02:58:40   

Thanks for sharing Gabe.

David Elizondo | LLBLGen Support Team