jQuery的:到asp.net web服务的Ajax调用失败,服务器返回500错误 [英] jQuery: Ajax call to asp.net webservice fails, server return 500 error

查看:132
本文介绍了jQuery的:到asp.net web服务的Ajax调用失败,服务器返回500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我创建了一个测试项目只是为了验证jQuery的Ajax的工作原理与asp.net服务,它也没有任何问题。我用在VS Studio中创建一个默认的HelloWorld服务。我呼吁通过jQuery的服务是这样的:

Ok, so I created a test project just to verify that jQuery AJAX works with asp.net service, and it does no problems. I used a default HelloWorld service created in VS studio. I am calling the service via jQuery like this:

在Default.aspx的:

in Default.aspx:

<script language="javascript" type="text/javascript">
    $(document).ready(function() {

        //test web service
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "TestService.asmx/HelloWorld",
            data: "{}",
            dataType: "json",
            success: function(msg) { alert(msg);},
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                debugger;
            }
        });
    });
</script>

在TestService.asmx

in TestService.asmx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebServiceTestWitJQuery
{
    /// <summary>
    /// Summary description for TestService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class TestService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

我接着和精确复制一切,因为它是在我的项目,这是行不通的。我得到一个500服务器错误。

I then proceeded and copied everything exactly as it is in my project and it does not work. I get a 500 server error.

我验证了以下内容:

  1. web.configs相同
  2. 页相同
  3. 在服务类相同
  4. 在jQuery的AJAX调用相同
  5. 我可以导航到的http://本地主机:3272 / TestService.asmx OP =的HelloWorld 和互联网服务工作正常。
  1. web.configs identical
  2. pages identical
  3. service class identical
  4. jquery ajax call identical
  5. I can navigate to http://localhost:3272/TestService.asmx?op=HelloWorld and webservice works fine.

还有什么呢?

推荐答案

想通了。如果不知道发生了什么使用小提琴手。这清楚地表明,服务器无法创建服务类的一个实例,因为它是在错误的命名空间。我R·禁用并没有注意到,我并没有改变服务的命名空间。问题解决了。

Figured it out. When not sure what is happening use Fiddler. It clearly shows that server could not create an instance of the service class because it was in the wrong namespace. I had R# disabled and did not notice that I did not change the namespace of the service. Problem solved.

这篇关于jQuery的:到asp.net web服务的Ajax调用失败,服务器返回500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆