Showing posts with label calls. Show all posts
Showing posts with label calls. Show all posts

Wednesday, March 28, 2012

Ajax beta2 -> RTM > JSON Serialization exception when calling a dataservice

Hi all, I must migrate an application from Ajax beta2 to RTM version and I experienced a serious problem.This application uses xml-script that calls some webservices (more specifically dataservices) to fill in objets. These calls throw json serialization exceptions, whatever the returned type.I then wanted to try with a "fresh" web project, I thus created a new project, and then created a small web service inherited from the dataservice class. I placed a typical example of a sample dataservice from internet into my dataservice. Then I used Fiddler to emulate the dataservice call from the script (ie doing a POST with loadmethod parameters etc…), and this simple code produces a serialization exception.The only information I found is herehttp://www.oreilly.com/catalog/atlas/update/version1.0-update.pdf (chapter 9). This chapter is about the same subject, and the author is experience the same trouble in the same circumstances. Christophe Below is the complete exception:

{"Message":"A circular reference was detected while serializing an object of type \u0027System.Reflection.Module\u0027.","StackTrace":" à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n à System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

The latest release does not support DataSet, DataTables or the Xml Script. You have to add the Preview to work with these objects.


Have you install framework 2.0?


I am using Microsoft.Web.Preview from the the "ASP.NET Futures May 2007" package (assembly version 1.1.61025.0).

I do not use complex objets like Dataset, Datatables,...

The sample code was picked up fromhttp://aspalliance.com/1302_Unveil_the_Data_Binding_Architecture_inside_Microsoft_ASPNET_Ajax_10__Part_2#Page2, but even a string does not serialize !

Note that the call stack shows an exception within System.Web.Script.Serialization, which is in Ajax Extensions, not in futures ...

Christophe.


No, we have no answer at this time.


Hi chrisrodri,

Has your problem been resolved yet ? Would you share your solution(resolved) or new findings?


Hi all,

I finally solved this issue. I have to add these threw following lines into the web.config (in jsonSerialization/converters section):

<addname="DataSetConverter"type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter"/>
<addname="DataRowConverter"type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter"/>
<addname="DataTableConverter"type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter"/>

I do not understand why these lines are needed because i do not use any DataTable or DataRow, just generics Lists that are not dependant of these ones.... but it works !

Monday, March 26, 2012

AJAX asynchronous calls without update panel

Is the UpdatePanel always needed to make Asynchronously calls to the server? I was catching up with the client side capabilities for the framework using the $get and $sys client classes and seem to provide a lot of functionality. Any samples, tutorials where I can go to get some reference. I went through the AJAX framwework documentation but no help.

No, you can also use webservices or pagemethods take a look at these links:

http://www.asp.net/ajax/documentation/live/overview/AsynchronousLayerOverview.aspx

http://www.asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

http://www.asp.net/ajax/documentation/live/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

Hope this helps,
Elias.

Saturday, March 24, 2012

Ajax and Session when WebServices called from client site

I have been trying to find a solution for session state and AJAX web service calls. I have a simple page that reports different session id than the web service called from AJAX client site. There are lots of discussions of this topic but no real answers.

Am I lost? Is it that each web service calls from the client site are associated always different session?

How can I limit the web services to be called from client when they don't have session in server?

Or is this something I have to do by using the AJAX authentication services?

What about if webservice needs to access the session state variables how this can be accomplished as they have different session ids?

Regards,

Alexander

A unique session ID and a session object is not associated with a session until a session variable is added to the Session. You should assign to and create at least one session variable like following:

Session["__Dummy"] = "Some Value";

After you do this the session Id will remain constant for the session.


Yes, that was the magic... solved my problem.

Thanks...