简体   繁体   English

WCF Web服务中止

[英]WCF Web service getting aborted

I have following Webservice returning JSON : 我有以下Web服务返回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: 在客户端,我正在按以下方式调用Web服务:

   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? 但是ajax调用总是会中止....如果我在webservice中添加断点..它也会被击中两次.... ?? .... webservice代码似乎已正确执行..但浏览器中的状态已中止?

Found the Solution.....It Seems WCF Doesn't allow DateTime null values... I have public DateTime SortDateTime { get; set; } 找到解决方案.....似乎WCF不允许DateTime空值...我有public DateTime SortDateTime { get; set; } public DateTime SortDateTime { get; set; } public DateTime SortDateTime { get; set; } which was not assigned any value.. public DateTime SortDateTime { get; set; } ,未分配任何值。

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. 我遇到了同样的问题,因为我从服务器返回了大量记录,我将以下行添加到我的wcf配置文件中,它可以正常工作。

<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; 问题或错误是序列化时的Javascript对象表示法; not in WCF. 不在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." “•JavaScript日期基于自1970年1月1日午夜以来的毫秒数的时间值。一天保持86,400,000毫秒。相对于1970年1月1日,JavaScript Date对象的范围是-100,000,000天至100,000,000天。

DateTime with value Year=1, Month=1, and Day = 1..31 throw exception. 日期时间值Year = 1,Month = 1和Day = 1..31的DateTime引发异常。 where Year = 1..yyyy, Month = 2..MM, Day=1..DD and so on works fine. 其中Year = 1..yyyy,Month = 2..MM,Day = 1..DD,依此类推。 ("MyDateTime":"/Date(-62132950800000+0000)/") ( “MyDateTime”: “/日期(-62132950800000 + 0000)/”)

I did a massive test with 'DateTime', but the problem is within the limits. 我使用“ DateTime”进行了大规模测试,但问题在极限范围内。

As DateTime is a ValueType then null values do not is allowed, but Nullable<DateTime> also works fine.("MyDateTime":null) 由于DateTime是ValueType,因此不允许使用空值,但是Nullable<DateTime>也可以正常工作。(“ MyDateTime”:null)

I had the same problem today. 我今天有同样的问题。 (thanks Shashank Kumar) (感谢Shashank Kumar)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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