Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Tuesday, June 19, 2007

What if you had a web service method like this:

[WebMethod]
public List<String> Test() {
List<String> blah = new List<string>();
blah.Add("First");
blah.Add("Second");

return blah;
}

The method returns a generic List<> type of String objects. What happens if you want to consume it from AJAX via a web service method call like this?

function callWebService()
{
WebService.Test(OnMethodSucceeded,OnMethodFailed);
return;
}

The result will get sent back to the browser as an array type in JavaScript. Doing an alert() call on the result returned from OnMethodSucceeded like this:

function OnMethodSucceeded(result, eventArgs)
{
alert(result);
}

Yields the string "First,Second". You may also index into the array too and get the individual strings.

So, what about parameters? ECMA script doesn't support generics in the same way .NET does, but given that we've identified the runtime returns the generic list as an array back to ECMA script, it seems logical that we could pass a "generic list" to the runtime via ECMA script as an array. Indeed, we can. If we change the web service method to something like this:

[WebMethod]
public String Test(List<String> arg) {
if (arg.Count > 0)
return arg[0];
else
return "NA";
}


We can call it from script like this:

function callWebService()
{
var arr= new Array(5)
arr[0]="1";
arr[1]="2";
arr[2]="3";
arr[3]="4";
arr[4]="5";
WebService.Test(arr,OnMethodSucceeded,OnMethodFailed);
return;
}

The web service method returns, as a string, the first item in the array. OnMethodSucceeded, with our alert() method, will display "1" returned to the client.


kick it on DotNetKicks.com
Tuesday, June 19, 2007 9:10:20 AM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
AJAX | ASP.Net | JavaScript
Tracked by:
http://freewebs.com/aspxfaq/05/sitemap8.html [Pingback]
http://freewebs.com/toltom/04/sitemap7.html [Pingback]
http://freewebs.com/toltom/16/radisson-deauville-resort.html [Pingback]
http://freewebs.com/toltom/09/sitemap13.html [Pingback]
http://freewebs.com/toltom/08/sony-digital-cameras.html [Pingback]
"http://kevruublog.tripod.com/88.html" (http://kevruublog.tripod.com/88.html) [Pingback]
"http://fartooblog.tripod.com/18.html" (http://fartooblog.tripod.com/18.html) [Pingback]
"http://apz50e.org/sitemap55.html" (http://apz50e.org/sitemap55.html) [Pingback]
"http://apz50e.org/grannyjoy-com.html" (http://apz50e.org/grannyjoy-com.html) [Pingback]
"http://topslots.nl.eu.org/01/sitemap14.html" (http://topslots.nl.eu.org/01/site... [Pingback]
"http://freewebs.com/amexa/42/nerf-bars.html" (http://freewebs.com/amexa/42/nerf... [Pingback]
"http://freewebs.com/amexa/48/dermatitis-herpetiformis.html" (http://freewebs.co... [Pingback]
"http://freewebs.com/amexa/21/fight-night-round-3.html" (http://freewebs.com/ame... [Pingback]
"http://pinofranc.homestead.com/00/cool-free-online-games.html" (http://pinofran... [Pingback]
"http://pinofranc.homestead.com/04/swimming-pool-pumps-san-antonio-texas.html" (... [Pingback]
"http://pinofranc.homestead.com/05/index.html" (http://pinofranc.homestead.com/0... [Pingback]
"http://wdall-xxx.com/celeberty-nude.html" (http://wdall-xxx.com/celeberty-nude.... [Pingback]
"http://aixpj-www.com/best-blowjob-ever.html" (http://aixpj-www.com/best-blowjob... [Pingback]
"http://nabkoonews.tripod.com/29.html" (http://nabkoonews.tripod.com/29.html) [Pingback]
"http://javboonews.netfirms.com/64.html" (http://javboonews.netfirms.com/64.html... [Pingback]
"http://caploonews.tripod.com/174.html" (http://caploonews.tripod.com/174.html) [Pingback]
"http://ywwhr-ooo.com/little-girl-pussy.html" (http://ywwhr-ooo.com/little-girl-... [Pingback]
"http://pohteenews.tripod.com/86.html" (http://pohteenews.tripod.com/86.html) [Pingback]
"http://smp6f-hhh.com/free-naked-men-pictures.html" (http://smp6f-hhh.com/free-n... [Pingback]
"http://y2zyu-xxx.biz/narkiss-nude.html" (http://y2zyu-xxx.biz/narkiss-nude.html... [Pingback]
"http://bdgvu-www.biz/fake-naked-pictures-of-14-year-old-girls.html" (http://bdg... [Pingback]
"http://omu8u-eee.com/adultdvdempire.html" (http://omu8u-eee.com/adultdvdempire.... [Pingback]
"http://freewebs.com/tferma/12/alcoholism-facts.html" (http://freewebs.com/tferm... [Pingback]
"http://freewebs.com/amexa/42/add-new-screen-names.html" (http://freewebs.com/am... [Pingback]
"http://freewebs.com/tiltak/14/messy.html" (http://freewebs.com/tiltak/14/messy.... [Pingback]
"http://freewebs.com/lcddlp/05/pcdi.html" (http://freewebs.com/lcddlp/05/pcdi.ht... [Pingback]
"http://freewebs.com/aspxtut/12/sally-mae-loans.html" (http://freewebs.com/aspxt... [Pingback]
"http://iyhzn-rrr.com/naked-slut-whores.html" (http://iyhzn-rrr.com/naked-slut-w... [Pingback]
"http://unibetkom.fw.bz/0087-blog.html" (http://unibetkom.fw.bz/0087-blog.html) [Pingback]
"http://ramambo.nl.eu.org/16/nike-id.html" (http://ramambo.nl.eu.org/16/nike-id.... [Pingback]
"http://harum.nl.eu.org/boys-gone-wild.html" (http://harum.nl.eu.org/boys-gone-w... [Pingback]
"http://ramambo.nl.eu.org/somebody-told-me.html" (http://ramambo.nl.eu.org/someb... [Pingback]
"http://nfdi1ek.biz/latino-blowjobs.html" (http://nfdi1ek.biz/latino-blowjobs.ht... [Pingback]
"http://voretom.nl.eu.org/huge-cocks-cumming.html" (http://voretom.nl.eu.org/hug... [Pingback]
"http://asfokom.nl.eu.org/pga-national-resort-and-spa.html" (http://asfokom.nl.e... [Pingback]
"http://mnbjoxr.com/closeup-clitoris-galleries.html" (http://mnbjoxr.com/closeup... [Pingback]
"http://cm8utr4.biz/www-the-hun-net.html" (http://cm8utr4.biz/www-the-hun-net.ht... [Pingback]
"http://freewebs.com/gabeganews/102.html" (http://freewebs.com/gabeganews/102.ht... [Pingback]
"http://cyisevw.com/baltimore-city-police.html" (http://cyisevw.com/baltimore-ci... [Pingback]
"http://suaxhmc.biz/sprint-relay-online.html" (http://suaxhmc.biz/sprint-relay-o... [Pingback]
"http://uro--blog.nl.eu.org/panty-slave.html" (http://uro--blog.nl.eu.org/panty-... [Pingback]
"http://ekdh9nx.biz/religious-newspapers-in-us.html" (http://ekdh9nx.biz/religio... [Pingback]
"http://nasferablog.netfirms.com/408.html" (http://nasferablog.netfirms.com/408.... [Pingback]
"http://cq7t5nv.biz/mitchellsales-com.html" (http://cq7t5nv.biz/mitchellsales-co... [Pingback]
"http://nasferablog.netfirms.com/561.html" (http://nasferablog.netfirms.com/561.... [Pingback]
"http://nuo--kom.nl.eu.org/tight-holes.html" (http://nuo--kom.nl.eu.org/tight-ho... [Pingback]
"http://sero--kom.nl.eu.org/greetingscards.html" (http://sero--kom.nl.eu.org/gre... [Pingback]
"http://dhqldvz.biz/bondage-sex-bed.html" (http://dhqldvz.biz/bondage-sex-bed.ht... [Pingback]
"http://nrpfka3.biz/rufus-sewell.html" (http://nrpfka3.biz/rufus-sewell.html) [Pingback]
"http://nasferablog.netfirms.com/441.html" (http://nasferablog.netfirms.com/441.... [Pingback]
"http://jmqp7tr.biz/newyorklottey.html" (http://jmqp7tr.biz/newyorklottey.html) [Pingback]
"http://hjftsic.biz/loancalculater.html" (http://hjftsic.biz/loancalculater.html... [Pingback]
"http://freewebs.com/fremapblog/sitemap4.html" (http://freewebs.com/fremapblog/s... [Pingback]
"http://freewebs.com/sruone/free-porn-365.html" (http://freewebs.com/sruone/free... [Pingback]
"http://freewebs.com/sruone/sitemap374.html" (http://freewebs.com/sruone/sitemap... [Pingback]
"http://lopbafrea.homestead.com/24.html" (http://lopbafrea.homestead.com/24.html... [Pingback]
"http://pk3p6fu.info/cancell.html" (http://pk3p6fu.info/cancell.html) [Pingback]
"http://freewebs.com/vuter/16/mach-com.html" (http://freewebs.com/vuter/16/mach-... [Pingback]
"http://cuter.homestead.com/00/craftmatic.html" (http://cuter.homestead.com/00/c... [Pingback]
"http://buter.homestead.com/00/sitemap3.html" (http://buter.homestead.com/00/sit... [Pingback]
"http://duter.homestead.com/01/www-ultimatebet.html" (http://duter.homestead.com... [Pingback]
"http://freewebs.com/datingblogger/227.html" (http://freewebs.com/datingblogger/... [Pingback]
"http://freewebs.com/datingblogger/176.html" (http://freewebs.com/datingblogger/... [Pingback]
"http://fasxen.netfirms.com/17.html" (http://fasxen.netfirms.com/17.html) [Pingback]

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)