创建新的asmx页面时出现问题 [英] Problem while create a new asmx page

查看:77
本文介绍了创建新的asmx页面时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在创建一个asmx网络服务。

在visual studio 2012中项目名称我右键单击并添加Web服务名称 UserDetails.asmx



现在我正在尝试在js文件中使用Web服务。像这样

Hi all

I am creating an asmx web service.
In visual studio 2012 on the project name I right clicked and added an web service name UserDetails.asmx

Now I am trying to use the web service in the js file. like this

$.ajax({
       type: "POST",
       url: "UserDetails.asmx/HelloWorld",
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (data) {
          alert('success');
       },
       error: function () {
           alert("Error");
       }
   });





显示错误 POST http://192.168.9.185/GPS/UserDetails.asmx/HelloWorld 500(内部服务器错误)



我的代码中是否有任何错误或者我遗漏了某些内容以致显示错误。

我的Asmx页面



Its showing error that POST http://192.168.9.185/GPS/UserDetails.asmx/HelloWorld 500 (Internal Server Error)

Is there any fault in my code or I am missing something so that its showing error.
My Asmx Page

<%@ WebService Language="C#" CodeBehind="~/App_Code/UserDetails.cs" Class="UserDetails" %>



我的代码背后


My Code Behind

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

/// <summary>
/// Summary description for UserDetails
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 UserDetails : System.Web.Services.WebService {

    public UserDetails () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

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



请帮我解决问题



提前致谢


Please help me to solve the problem

Thanks in advance

推荐答案

.ajax({
type: POST
url: UserDetails.asmx / HelloWorld
contentType: application / json; charset = utf-8
dataType: json
成功: function (data){
alert(' success');
},
错误: function (){
alert( 错误);
}
});
.ajax({ type: "POST", url: "UserDetails.asmx/HelloWorld", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { alert('success'); }, error: function () { alert("Error"); } });





显示错误 POST http://192.168.9.185/GPS/UserDetails.asmx/HelloWorld 500(内部服务器错误)



我的代码中是否有任何错误或者我遗漏了某些内容以致显示错误。

我的Asmx页面



Its showing error that POST http://192.168.9.185/GPS/UserDetails.asmx/HelloWorld 500 (Internal Server Error)

Is there any fault in my code or I am missing something so that its showing error.
My Asmx Page

<%@ WebService Language="C#" CodeBehind="~/App_Code/UserDetails.cs" Class="UserDetails" %>



我的代码背后


My Code Behind

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

/// <summary>
/// Summary description for UserDetails
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 UserDetails : System.Web.Services.WebService {

    public UserDetails () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

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



请帮我解决问题



提前致谢


Please help me to solve the problem

Thanks in advance


取消注释 [System.Web.Script.Services.ScriptService]



这样你就可以在js文件中使用这个web方法
Just uncomment the [System.Web.Script.Services.ScriptService]

So that you can use this web method in the js file


这篇关于创建新的asmx页面时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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