I have a web method that is being called from jQuery ajax, for example:
$.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 fix the format, the DoSomething methods are executed and retain the original json for the database. But if myClass is wrong, the method fails at all, and I cannot register the problematic json ...
What is the best way to always get and write the raw json that my web method gets, even if serialization fails?
source
share