I have a web method, which is called from jquery's ajax method, like this:
$.ajax({
type: "POST",
url: "MyWebService.aspx/DoSomething",
data: '{"myClass": ' + JSON.stringify(myClass) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (result) {
alert("success");
},
error: function () {
alert("error");
}
});
And this is my web method:
[WebMethod(EnableSession = true)]
public static object DoSomething(MyClass myClass)
{
HttpContext.Current.Request.InputStream.Position = 0;
using (var reader = new StreamReader(HttpContext.Current.Request.InputStream))
{
Logger.Log(reader.ReadToEnd());
}
}
If myClass in javascript is serialized to correct format, then DoSomething methods executes and saves the raw json to database. But if myClass is in wrong then the method doesn't execute at all and I can't log the problematic json...
What is the best way to always somehow get and log the raw json, that my web method receives, even if the serialization fails?