代码在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之外的所有浏览器。
[UPDATE]
好的,这是一个有趣的更新
当我调用SaveILO函数时,响应返回上面发布的错误
但是当我在错误响应之后立即调用该函数时,它第二次就会成功。