在上一篇文章(基于ASP.NET 3.5 Web Service 的JSON扩展应用)中已经讲过,JSON - JavaScript对象符号是默认序列化格式,使用它进行数据转换 之间客户端服务器请求。您可以禁用所有目前启用的协议像HTTP-GET、HTTP-POST,甚至的XML格式的SOAP中使用的早期形式的Web服务。以下设置在
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>AJAX Web Form</title> <script type="text/javascript"> function CallNextDate() { AjaxWebService.Service.getNextBackupDate(1, OnSucceeded); }
function CallHelloWorld() { AjaxWebService.Service.HelloWorld(OnSucceeded); } function CallBookTitle() { AjaxWebService.Service.GetBookTitle(OnSuccess, OnFail, "XmlDocument"); }
// This is the callback function that processes the Web Service return value in JSON format. function OnSucceeded(result) { var myresult = document.getElementById("Text1"); myresult.value = result; }
// This is the callback function that processes the Web Service return value in XML format. function OnSuccess(result) { var myresult = document.getElementById("Text1"); myresult.value = "Title: " + result.documentElement.text; }
// This is the callback function that processes the Web Service return value in XML format. function OnFail(error) { var myresult = document.getElementById("Text1"); myresult.value = "Service Error: " + error.get_message(); } </script>