First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

If you want to access a web service from an ASP.NET Ajax page or from a Silverlight 2.0 app, you have to decorate it with the ScriptService attribute. This will enable the creation of a JavaScript proxy to call the web service using the JSON notation.

The generated proxy will call the web service using the HTTP POST method. But what if you want to use the GET method? There is another attribute that you can specify to fine tune the response of a single method: ScriptMethod.

Among the possible tuning, you can specify that you want to use GET by setting the UseHttpGet property to true:

[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string EchoInput(string input)
{
    return "You entered " + input;
}

But this is not enough since be default webservices will not listen for GET, and will raise a "method not supported" error if called with the GET verb.

In order to enable the GET you also have to make a few changes inside the web.config file of your web application (like the ones to enable HTTP POST):

<system.web>
    ...
    <webServices>
        <protocols>
              <add name="HttpGet"/>
        </protocols>
    </webServices>
    ...
</system.web>

But be careful when using the GET verb to call a web service: use it only for safe operations, don't expose sensitive data and only for retrieval operations.

posted on Monday, December 3, 2007 11:24 PM
Comments have been closed on this topic.