JQuery: Ajax call for asp.net webservice fails, 500 server return error

Ok, so I created a test project to make sure jQuery AJAX works with the asp.net service and there are no problems. I used the default HelloWorld service created in VS studio. I call the service through jQuery as follows:

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>

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";
        }
    }
}

Then I continued and copied everything in my project and it does not work. I get a 500 server error.

I checked the following:

What else?

+3
6

. , , Fiddler. , , . R # , . .

+2

, jQuery, ASP.NET.

jQuery , json. "Hello World", , , json. 'dataType: "json",' param jQuery , .

, , jQuery, - RESTful, - WSDL. asp.net, , REST.

+1

URL- Script, URL-. - . : URL:localhost:1111/TestService.asmx/HelloWorld

0

. , , , - .

i ajax 500 .

contentType: "application/json; charset=utf-8",
        data: "{}",
        dataType: "json",
0

, , WebService .

[WebMethod]
public MyData GetMyData() {...}

[WebMethod(EnableSession = true)]
public MyData GetMyData() {...}

. : ASP.NET WebService

0

, (VS2015,.Net4.0, ajax- WebForms , ). , HttpPost :

<system.web>
    <webServices>
     <protocols> 
    <add name="HttpGet" /> -- just for direct testing : delete this line after 
    <add name="HttpPost" />
     </protocols>
     </webServices>
</system.web>
0

Source: https://habr.com/ru/post/1727775/


All Articles