ASP.NET Podcast Show #101 - ASP.NET AJAX Futures Data - Video and Audio
Subscribe <-- What everyone should be doing.
Download WMV <-- The old style way of doing it.
Download MP4 for Ipod and Zune <-- ditto
Download MP3 <-- ditto
Original url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2007/09/21/asp-net-podcast-show-101-asp-net-ajax-futures-data.aspx
Show Notes:
Web.config additions:
<
scripting><webServices><
jsonSerialization><converters><
add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview"/><add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview"/> <add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview"/></
converters>Web Service Codeusing
System;using
System.Collections;using
System.ComponentModel;using
System.Data;using
System.Linq;using
System.Web;using
System.Web.Script.Services;using
System.Web.Services;using
System.Web.Services.Protocols;using
System.Xml.Linq;using
Microsoft.Web.Preview.Services;/// <summary>///
Summary description for WebService///
</summary>[WebService(Namespace = "http://tempuri.org/")][
WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[
ScriptService]public
class WebService : DataService{
public WebService(){
//Uncomment the following line if using designed components //InitializeComponent();}
[WebMethod]public string HelloWorld(){
return "Hello World";}
[
WebMethod][DataObjectMethod(DataObjectMethodType.Select)]public DataSet GetValues(int i){
DataSet ds = new DataSet();DataTable dt = new DataTable(); DataRow dr;dt.Columns.Add(new DataColumn("Name"));dt.Columns.Add(new DataColumn("ID", Type.GetType("System.Int32")));dr = dt.NewRow();
if (i % 2 == 0){
dr[
"Name"] = "Wally McClure";dr["ID"] = 1;}
else{
dr["Name"] = "Paul Glavich";dr["ID"] = 2;}
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return (ds);}
}
JavaScript code:function pageLoad() {WebService.GetValues(1, OnCompletion);
}
function OnCompletion(results){
var
dataOutput = "";var
divOutput = $get("Output");var strReturn = "<br />";dataOutput =
"Dataset: " + strReturn;for(m in results){
dataOutput += m + strReturn;
}
dataOutput +=
"DataTable: " + strReturn;for(m in results.tables[0]){
dataOutput += m + strReturn;
}
dataOutput +=
"Rows: " + strReturn;for(m in results.tables[0].rows){
dataOutput += m + strReturn;
}
dataOutput +=
"Rows[0]: " + strReturn;for(m in results.tables[0].rows[0]){
dataOutput += m + strReturn;
}
dataOutput +=
"Rows[0].Name: " + strReturn;for(m in results.tables[0].rows[0].Name){
dataOutput += m + strReturn;
}
dataOutput +=
"Columns: " + strReturn;for(m in results.tables[0].columns){
dataOutput += m + strReturn;
}
dataOutput +=
"Columns[0]: " + strReturn;for(m in results.tables[0].columns[0]){
dataOutput += m + strReturn;
}
dataOutput += "rows[0].Name: " + results.tables[0].rows[0].Name + strReturn;dataOutput +=
"Columns[0].dataType: " + results.tables[0].columns[0].dataType + strReturn;dataOutput += "Columns[1].dataType: " + results.tables[0].columns[1].dataType + strReturn;dataOutput +=
"Columns[1].isKey: " + results.tables[0].columns[1].isKey + strReturn;divOutput.innerHTML = dataOutput;}