Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
JavaScript
$.ajax({
       type: "POST",
       url: "UserDetails.asmx/HelloWorld",
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (data) {
          alert('success');
       },
       error: function () {
           alert("Error");
       }
   });


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
HTML
<%@ WebService Language="C#" CodeBehind="~/App_Code/UserDetails.cs" Class="UserDetails" %>

My Code Behind
C#
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
Posted

1 solution

Just uncomment the [System.Web.Script.Services.ScriptService]

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900