When a Web service is invoked asynchronously using the ASP.net Ajax asynchronous communication layer, the HTTP POST method is applied by default. But in order to provide sufficient flexibility, the ASP.net Ajax asynchronous communication layer also allows us to invoke using HTTP GET.
When invoked using an HTTP GET, the parameters of the method are serialized into a JSON string, which is then coded and added to the URL to be sent back to the server for processing. The comparison of Get and default post methods has been described in detail in chapter 2nd and is not repeated here.
If you want to call a method in a Web service in the form of an HTTP GET, add the [Scriptmethod = True] property to the method. For example, for example programs in section 3.1, we can modify the definition of the method in the server-side Web service as follows, and note the bold part:
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string SayHelloUsingGET(string name)
{
return string.Format("Hello {0}!", name);
}
Run the sample program again and open the HTTP sniffer to see that this asynchronous call does use HTTP GET. As shown in Figure 3-9.
When using HTTP GET requests for Web service, pay special attention to security issues. In general, you can use HTTP GET only if you are not exposed to sensitive information and do not have critical operations such as deleting/updating data.
Figure 3-9 Invoking the Web service using HTTP GET