我正在为移动设备开发一个网站,该网站使用 jQuery (v 1.7.2) 对 ASP.NET (v 2.0.50727) Web 服务进行 ajax 调用。
调用在大约 95% 的时间内正常工作,但它会随机失败,返回 500 内部服务器错误。它在第一行代码执行之前在服务器端失败(第一行写入事件日志)。
我还没有看到使用我记得的桌面浏览器调用失败,但我已经看到使用 iPad 失败了。我添加了
<browserCaps userAgentCacheKeyLength="256">
到 Web 服务的 web.config 文件,但这没有帮助。
javascript:
$.ajax({
type: "POST",
url: serverURL + "/getImage",
data: '{"formURL":"' + url + '", "rowNumber":"'+rowNumber+'"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg,textStatus, jqXHR) {
...
}, error: function(xhr, ajaxOptions, thrownError) {
...
}
}).done(function(){
console.log("getImage call is done");
});
传递给 Web 服务的示例数据:
'{"formURL":"fileName.xml", "rowNumber":"1"}'
C#
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string getImage(string formURL, string rowNumber) {
log("Retrieving image of form " + formURL);
string image = "";
string username = /*retrieve username*/;
string password = /*retrieve password*/;
if (username != null && username != "") {
image = /*code to retrieve the image*/;
}
return image;
}
private void log(string message) {
EvLog.WriteToEventLog(DateTime.Now.ToString("MM:dd:yyyy H:mm:ss:fff") + Environment.NewLine + message, 10);
}
我发现唯一对我有一点帮助的是,当调用失败时,因为来自 Web 服务的响应标头包含“jsonerror:true”,尽管我无法确定它为什么会随机失败。
任何帮助表示赞赏!