0

代码在 Chrome、IE9、FF 中完美运行,win7 上的 Safari 除外。
还没有在 ipad 上尝试过 Safari。
发送到服务器的数据在 safari 控制台中看起来很好。

这是失败时返回给客户端的错误。

    {
        "ExceptionDetail":{
            "HelpLink":null,
            "InnerException":{
                "HelpLink":null,
                "InnerException":null,
                "Message":"The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).",
                "StackTrace":"   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRequest(Message message, Object[] parameters)",
                "Type":"System.Runtime.Serialization.SerializationException"
            },
            "Message":"Error in deserializing body of request message for operation 'SaveILOData'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).",
            "StackTrace":"   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRequest(Message message, Object[] parameters)\u000d\u000a   at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)\u000d\u000a   at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)\u000d\u000a   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)",
            "Type":"System.ServiceModel.CommunicationException"
        },
        "ExceptionType":"System.ServiceModel.CommunicationException",
        "Message":"Error in deserializing body of request message for operation 'SaveILOData'. The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true).",
        "StackTrace":"   at System.ServiceModel.Dispatcher.PrimitiveOperationFormatter.DeserializeRequest(Message message, Object[] parameters)\u000d\u000a   at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)\u000d\u000a   at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)\u000d\u000a   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)\u000d\u000a   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)"
    }




这是仅在 Safari 上调用错误函数的 JavaScript

    function SaveILO(exitEditor) {
        var templateID = $("#<%=DropDownListAssetTypes.ClientID%>").val();
        var dataValue = jseditor.getValue();
        var json = JSON.stringify({ "iloID": "<%=Request.QueryString["id"]%>", "iloData": dataValue, "iloTypeID": templateID });
        $.ajax({
            cache: false,
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            processdata: false,
            url: '../services/jsonservices.svc/SaveILOData',
            data: json,
            success: function (msg) {
                SetStatusMessage('');
                if (exitEditor)
                    top.document.location.href = '../';
                //parent.location.href = parent.location.href;
            },
            error: function (msg, textStatus) {
                alert("There was an error saving the ILO." );
            },
        });
    }




这里是服务

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public string SaveILOData(string iloID, string iloData, int iloTypeID)
    {
        using (ILOManagerRepository dc = new ILOManagerRepository())
        {
            dc.AddEditILOData(iloID, iloData,iloTypeID);
        }
        return "success";

    }




这里是保存函数 ILOManagerRepository

    public string AddEditILOData(string identifier, string iloData, int iloTypeID)
    {
        ILOData d = GetILODataByIdentifier(identifier);
        ILO i = GetILOByIdentifier(identifier);

        if (d == null)
        {
            d = new ILOData();
            db.ILODatas.Add(d);
        }

        i.TypeID = iloTypeID;
        d.ILOID = i.ILOID;
        d.Data = iloData;
        d.LastUpdated = DateTime.Now;

        db.SaveChanges();

        return d.ILODataID.ToString();
    }

正如你所看到的,这里没有什么特别的事情发生,它适用于除 Safari 之外的所有浏览器。

[更新]
好的,这是一个有趣的更新。
当我调用 SaveILO 函数时,响应会返回上面发布的错误。
但是,当我在第二次错误响应之后立即调用该函数时,它将成功。

4

0 回答 0