Reputation: 1220
I have following Webservice returning JSON :
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
public SomeResultClass AddObject(InputObject objInputObject)
{
IO objIO = new IO();
return objIO.AddObject(objInputObject);
}
on client side I am calling the webservice as following:
var Data=new Object();
Data.objInputObject=new Object();
//Add fields
$.ajax({
type: "POST",
data: JSON.stringify(Data),
dataType: "json",
async:false,
url: "../Webservice/WSService.svc/AddObject",
contentType: "application/json",
success: function (result) {
show_Result(result.AddObjectResult);
},
error: function (msg) {
show_Error(msg);
}
});
But the ajax call always gets aborted....also if I add breakpoint in webservice ..it is hit twice....??....the webservice code seem to be executed properly.. but status in browser is aborted?
Upvotes: 0
Views: 568
Reputation: 718
The problem or error is in Javascript Object Notation when serialize; not in WCF.
DateTime with value Year=1, Month=1, and Day = 1..31 throw exception. where Year = 1..yyyy, Month = 2..MM, Day=1..DD and so on works fine. ("MyDateTime":"/Date(-62132950800000+0000)/")
I did a massive test with 'DateTime', but the problem is within the limits.
As DateTime is a ValueType then null values do not is allowed, but Nullable<DateTime>
also works fine.("MyDateTime":null)
I had the same problem today. (thanks Shashank Kumar)
Upvotes: 0
Reputation: 1220
Found the Solution.....It Seems WCF Doesn't allow DateTime
null values...
I have public DateTime SortDateTime { get; set; }
which was not assigned any value..
Just changed model class constructor to initialize it :
public class InputObject
{
public InputObject ()
{
SortDateTime = DateTime.Now;
}
//Fields
public DateTime SortDateTime { get; set; }
}
Upvotes: 1
Reputation: 4489
I had the same problem because I was returning a large amount of record from the server, i added the following line to my wcf config file and it worked.
<system.web>
<httpRuntime maxRequestLength ="262144" executionTimeout="103600"/>
</system.web>
Hope it also work for you.Please try.
Upvotes: 0