Testing a web method (with browser/Fiddler)

Jag picture Jag · Apr 25, 2012 · Viewed 7.7k times · Source

I'm trying to implement the Jquery autocomplete by DevBridge(http://www.devbridge.com/projects/autocomplete/jquery/). This makes an AJAX call and in their example it uses a .NET web service. I am planning on using a web method.

I've created a page called WebMethodTest.aspx and added a simple web method to it. Code is as follows:

using System;
using System.Web.Services;

public partial class WebMethodsTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e) { }

    [WebMethod]
    public static string Test()
    {
        return "blah blah blah";
    }
}

I've added nothing to the web.config or done any other setup.

Calling the URL via a browser and fiddler (http://myurl/WebMethodTest.aspx/Test) returns nothing.

I am assuming I can make a normal HTTP request and it will return the string "blah blah blah".

Please note: I have done extensive searching to see if there's anything obvious I've missed. Numerous similar questions are here on SO and elsewhere but many revolve around malformed JSON etc. I am thinking my web method is just not being called.

So:

  1. Is making a normal HTTP request a valid way of checking a web method? If not, how?
  2. Can a web method be tested without the client side AJAX part?

NB: I see lots of "solutions" that mention enabling web methods in the ScriptManager - I thought this is only relevant when using ASP.NET AJAX (I'm not).

What little hair I have left is getting thinner. All suggestions welcome :)

ta

EDIT I reckon the URL I was testing against (the third party one that did return a JSON string) may have been something other than a web method. I assumed that mine should return a response to the browser too - it was a bad assumption.

As pointed out by @mgnoonan, Is it possible to make JSON requests using Fiddler's Request Builder?, has the correct syntax for testing with Fiddler.

What I used was:

POST http://xxx/WebMethods/WebMethodsTest.aspx/Test

and

User-Agent: Fiddler
Host: xxx
Content-Type: application/json; charset=utf-8
Content-Length: 0

This returned the expected string. :)

PS is there any way of marking a comment as an answer?

Answer