10 Replies - 1099 Views - Last Post: 06 August 2013 - 11:14 AM Rate Topic: -----

#1 flurg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-August 13

Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 07:29 AM

Hi all,

My fellow team member is away this week so I'd really appreciate if any of you can help me solve this problem I'm having.

I'm creating a very large tree in HTML (basically a lot of nested ul and li tags that I style and apply Javascript to). My initial thought was to use KnockoutJS (something we already use in the product) to call a C# web service which would return an object of TreeNode with the children of each node correctly nested in the object (up to a depth of 4).

I wrote my generic TreeNode object and it works perfectly. I've got it fully populated and it's all correct. It's not working when I try and pass it back from my web service though. I'm almost 100% certain this is due to the length of the JSON string I'm trying to send back. The TreeNode object isn't exactly simple, so parsed into JSON I would imagine it's pretty large. I've already added the setting to the web.config to ensure the max size of my JSON string is the max integer value but no luck. My tree has 2048 nodes in total and each node has 6 properties, so that's a lot of information to pass back.

My next thought was to build the tree gradually with various calls to get one node plus one level of it's children at a time, but if I don't include the deepest nodes in my calculation (as I won't be looking for children of these), that would mean roughly 1290 AJAX calls to build my tree which obviously is not going to be a good idea.

Do you any of you have any ideas on what I could look at as an alternative? Ideally I'd love to be able to use Razor to output the HTML I need but it's unfortunately not an option here.

The product I'm working on currently uses the TreeView control elsewhere and it runs extremely poorly (and doesn't even work at all in IE) which is why I'm looking for an alternative for this new part, with a view to replacing the poor TreeView control elsewhere further down the line.

I hope that's enough information to get you thinking.

Thanks,
Sarah

Is This A Good Question/Topic? 0
  • +

Replies To: Alternative to JSON / Ajax with ASP.NET and C#?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8948
  • View blog
  • Posts: 33,544
  • Joined: 12-June 08

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 07:38 AM

Why not have the webservice return back your blob of data and you format it the client?
Was This Post Helpful? 0
  • +
  • -

#3 flurg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-August 13

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 08:15 AM

That was my original plan but as I said, my web service won't return the full set of data and I'm pretty sure it's because it's exceeding the max length allowed for a JSON string, even though I've set the max length to int.MaxValue, as it's a pretty hefty amount of information.

View Postmodi123_1, on 06 August 2013 - 07:38 AM, said:

Why not have the webservice return back your blob of data and you format it the client?

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8948
  • View blog
  • Posts: 33,544
  • Joined: 12-June 08

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 08:22 AM

Sure.. then don't use a json string. Just plain ol' text. If need be use XML for a structure.
Was This Post Helpful? 0
  • +
  • -

#5 flurg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-August 13

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 08:36 AM

Just tried XML as I would definitely need the structure and plain text wouldn't provide that. Unfortunately that also doesn't return anything. The GET request is aborted in the same way it is when I'm trying to return it as JSON. I know it's not a problem with the code as if I simply return the first level of nodes it works fine, which is why I'm almost certain I'm exceeding the max length of what I can pass back.

Thanks for your suggestions anyway. I'll continue to scour Google :) Any other suggestions greatly appreciated!
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8948
  • View blog
  • Posts: 33,544
  • Joined: 12-June 08

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 08:41 AM

.. so how big is this string of data?
Was This Post Helpful? 0
  • +
  • -

#7 flurg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-August 13

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 08:52 AM

I'm not sure exactly. I do know there are 2,048 TreeNode's.

My TreeNode object has the following properties:
  • Parent
  • Children
  • Value


The Parent is a TreeNode object. The Children property is an array of TreeNode objects. The Value property is an object which has 6 further properties holding the information about the node such as ID, Name, Depth etc.

In the case of my data, I would have 1 TreeNode as the absolute root node. The children in that TreeNode would contain 16 TreeNode objects. Each of those will contain further TreeNode's in their Children properties etc etc until the tree is complete and all 2,048 nodes are stored in the object.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8948
  • View blog
  • Posts: 33,544
  • Joined: 12-June 08

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 08:53 AM

Hmm.. seems like an excessively large tree. What happens when you only return, say, the root and its sixteen children?

Wait a minute.. this display for the tree is an ASP.NET page, right? Why are you calling an webservice? Is this something you have control over? something you can just directly query the DB for?
Was This Post Helpful? 0
  • +
  • -

#9 flurg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 06-August 13

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 09:08 AM

Directly querying the DB is something I can do. The reason I picked the web service route was because I wanted to use KnockoutJS to consume the JSON and bind the returned information to produce my nested ul and li HTML code.

I'm assuming I could query the DB from my site and use a repeater control to produce my required HTML too, but it's not my preferred solution as I find it a bit messy. The MVVM pattern provided by KnockoutJS keeps the code much cleaner I find. I might have to give this a go though and see how it performs as it's currently the only alternative I can think of.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8948
  • View blog
  • Posts: 33,544
  • Joined: 12-June 08

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 09:13 AM

Sure, but if you want to get around a JSON string max length that's probably the best bet.
Was This Post Helpful? 0
  • +
  • -

#11 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Alternative to JSON / Ajax with ASP.NET and C#?

Posted 06 August 2013 - 11:14 AM

Have you tried breaking the tree into sections. If you have 6 parent nodes then have each of those be a separate request to the service to get the data specific to that node? So in your knockout view, if you're using an observableArray to load the nodes, you would change it to have 6 observableArrays instead of one. There's nothing that says you have to get all of your data in a single request.

This post has been edited by Nakor: 06 August 2013 - 11:15 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1