我知道这是一个经常被问到的问题,我已经尝试了所有的答案,但都没有用。当我使用 web 服务时,我没有收到任何错误消息,并且工作正常。但我每天都会收到 10-20 次此错误。所以确实有人遇到了这个错误,但我无法重现它。
这是错误堆栈跟踪。有帮助吗?
Exception stack trace:
at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
这就是我调用网络服务的方式:
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'MyWebService.asmx/MyWebService',
data: '{"id":"' + id+ '"}',
dataType: 'json',
success:
function(msg) {
// Do something
},
error:
function(XMLHttpRequest, textStatus, errorThrown) {
// Do something
}
});
这是我非常简单的网络服务:
[WebMethod(EnableSession = true)]
public string MyWebService(int id)
{
return "Something";
}
更新:
我在日志中看到,出现此错误时,用户代理始终是 Google 翻译。
http://translate.googleusercontent.com/translate_c?hl=es&prev=/search?q=test&hl=es&client=safari&tbo=d&rurl=translate.google.es&sl=en&u=http://www.mydomain .com&usg=ALkJrhhcOM9LJgtG-RhFx1XSQw-g4h_tbQ
你知道我怎样才能阻止这一切吗?
请您参考如下方法:
考虑到该错误仅在 google translate 请求您的服务时发生,是否可能 google translate 不会向您的服务方法发出 POST 请求而是 GET 请求?如果谷歌翻译使用 GET 请求,您的解决方案可能 be here停止这个问题。


