none
Overriding serialization in asmx webmethod response RRS feed

  • Question

  • Hi All,

    I am unsure if this has already been asked before or even if I am in the correct forum. Please bear with me and direct me to the correct answer/forum if so.

    I have an ASMX WebService project that has a few asmx pages that are set to expose many methods to separate projects being created in the company. So far it used to be only desktop applications that would be using the webservices (through SOAP), but now I need to cater for AJAX (Script) calls as well.

    My problem is that some of the current methods return DataTables and DataSets. Calling those methods over SOAP is no problem, but calling on AJAX throws a "System.InvalidOperationException" with the message "A circular reference was detected while serializing an object...". Serializing the DataTable/Set in the method itself using the JavaScriptSerializer and returning the string from the method solves this issue, but as it breaks all the existing products I am reluctant to force this change.

    Is there a way that I can 'override' the automatic serialization of the response in .Net, and use the standard (default) serialization process for all SOAP requests, while for AJAX requests, if it is returning DataTable/Set serialize using the JavaScriptSerializer or use the default otherwise? Or am I on a wild goose chase?

    Thank you for taking the time to read through this, I would be grateful for any help and suggestions.

    Cheers!


    Tuesday, August 20, 2013 1:13 AM

Answers

All replies