M
MattC
Hi,
I've got a webservice that returns a System.Drawing.Image. I'm calling the
webservice via AJAX all goes well but my JSON converter seralize method
gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred in
mscorlib.dll
Hope you can help.
TIA
MattC - code bellow
Service:
[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:
TestingGround.AJAXServices.LocalChartService.ChartDataTwo(SuccessCallBack,
FailedCallback);
And the callback on success
function OnCompleteImageService(results)
{
var obj = Sys.Serialization.JavaScriptSerializer.deserialize(results);
document.getElementById('ImageService').src = obj;
}
And my JSON Converter
class AjaxImageConvert : JavaScriptConverter
{
public override IDictionary<string, object> Serialize(object obj,
JavaScriptSerializer serializer)
{
Bitmap i;
//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;
Dictionary<string, object> result = new Dictionary<string,
object>();
result["CustomImage"] = i;
return result;
}
return new Dictionary<string, object>();
}
public override IEnumerable<Type> SupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new
Type[] { typeof(Bitmap) })); }
}
public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}
}
And registered
<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>
I've got a webservice that returns a System.Drawing.Image. I'm calling the
webservice via AJAX all goes well but my JSON converter seralize method
gets called repeatedly and causes a
An unhandled exception of type 'System.StackOverflowException' occurred in
mscorlib.dll
Hope you can help.
TIA
MattC - code bellow
Service:
[WebMethod]
[ScriptMethod]
public System.Drawing.Image ChartDataTwo(){...}
AJAX Call:
TestingGround.AJAXServices.LocalChartService.ChartDataTwo(SuccessCallBack,
FailedCallback);
And the callback on success
function OnCompleteImageService(results)
{
var obj = Sys.Serialization.JavaScriptSerializer.deserialize(results);
document.getElementById('ImageService').src = obj;
}
And my JSON Converter
class AjaxImageConvert : JavaScriptConverter
{
public override IDictionary<string, object> Serialize(object obj,
JavaScriptSerializer serializer)
{
Bitmap i;
//obj comes in as a Bitmap check why later
if (obj is Bitmap)
{
i = (Bitmap)obj;
Dictionary<string, object> result = new Dictionary<string,
object>();
result["CustomImage"] = i;
return result;
}
return new Dictionary<string, object>();
}
public override IEnumerable<Type> SupportedTypes
{
get { return new ReadOnlyCollection<Type>(new List<Type>(new
Type[] { typeof(Bitmap) })); }
}
public override object Deserialize(IDictionary<string, object>
dictionary, Type type, JavaScriptSerializer serializer)
{
object obj = (object)dictionary["CustomImage"];
return obj;
}
}
And registered
<jsonSerialization maxJsonLength="500000">
<converters>
<add name="AjaxImageConvert"
type="CustomControls.AjaxImageConvert"/>
</converters>
</jsonSerialization>