views:

189

answers:

3

Hi,

I'm trying to get more familiar with AJAX, and web services, so I have created the simplest of webservices with VS2008, hello world, with a webmethod GetPaper, and am trying to get the return value "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 consume this webservice with Javascript, I get a complete HTML page as a result, not just the value!

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

It's probably very simple, but I just can't seem to figure it out! Help is very much appreciated.

Regards,

Heras

edit: Or do I use a wrong URL? If so, what should I use?

+1  A: 

You might want to look at using a web reference in an ASP.NET scriptmanager instead of the basic GET request. This article should help you with that:

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

Steve Danner
Thank you for sharing that link, and sure, eventually I want to use .NET supporting AJAX functionality, but before I set off to start creating a more complex web application, I really want to learn the basics, what's really happening, and I immediately get stuck at the simplest task...I'm definitely going to dive into your link, so thanks!
Heras
+2  A: 

Should be more like this:

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 allow the GET action:

<webServices>
  <protocols>
    <add name=”HttpGet”/>
  </protocols>
</webServices>
Turnkey
Yes! That combination did the trick!I tried "helloworld.asmx/GetPaper" but that doesn't work without "add name=HttpGet" in the web.config.Thank you!
Heras
+1  A: 

I believe HTTP GET and POST are disabled by default. "INFO: HTTP GET and HTTP POST Are Disabled by Default"

Pete Nelson
Thanks! I will add both Get and Post to the web.config, to make sure I won't run into the same trouble in the future again.
Heras