简体   繁体   中英

WCF Web service getting aborted

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?

Found the Solution.....It Seems WCF Doesn't allow DateTime null values... I have public DateTime SortDateTime { get; set; } public DateTime SortDateTime { get; set; } 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; }
}

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.

The problem or error is in Javascript Object Notation when serialize; not in WCF.

"•The JavaScript date is based on a time value that is milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The JavaScript Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC."

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM