Why is my .NET webmethod returning a full HTML document instead of a return value?

I'm trying to get to know AJAX and web services, so I created the simplest of web services with VS2008, hello world, using the webmethod GetPaper and try to get the return value of "hello world".

<%@ WebService Language="C#" Class="HelloWorld" %> using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class HelloWorld : System.Web.Services.WebService { [WebMethod] public string GetPaper() { return "Hello World"; } } 

http://www.linkedpapers.com/helloworld.asmx

However, when I use this web service with Javascript, I end up with a full HTML page, not just the value!

 xmlRequest.onreadystatechange = ApplyUpdate; xmlRequest.open("GET", "http://www.linkedpapers.com/helloworld.asmx?op=GetPaper", true); xmlRequest.send(); 

This is probably very simple, but I just can't figure it out! Help is much appreciated.

Hi,

Heras

edit: Or am I using the wrong URL? If so, what should I use?

+4
source share
3 answers

Must have more:

 xmlRequest.onreadystatechange = ApplyUpdate; xmlRequest.open("GET", "http://www.linkedpapers.com/helloworld.asmx/GetPaper", true); xmlRequest.send(); 

Also make sure you configure your web.config to enable the GET action:

 <webServices> <protocols> <add name="HttpGet"/> </protocols> </webServices> 
+2
source

You might want to take a look at using a web link in your ASP.NET script manager instead of the main GET request. This article should help you with this:

http://msdn.microsoft.com/en-us/magazine/cc163499.aspx

+1
source

I believe that HTTP GET and POST are disabled by default. "INFO: HTTP GET and HTTP POST are disabled by default"

+1
source

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


All Articles