Tuesday, May 15, 2007

I talked at a high level about the new System.UriTemplate API in my post last week on the Zen of the Web Programming Model but there's definitely more to drill into.

As a start, here's some more extensive sample code that shows the basics of Bind() and Match():

using System;
using System.Collections.Specialized;

//To run this sample locally, create a new Console Application Project and
//add a reference to Microsoft.ServiceModel.Web.dll
public class BasicUriTemplate
{
    public static void Main()
    {
        Uri prefix = new Uri("http://localhost/");

        //A UriTemplate is a "URI with holes". It describes a set of URI's that
        //are structurally similar. This UriTemplate might be used for organizing
        //weather reports:
        UriTemplate template = new UriTemplate("weather/{state}/{city}");

        //You can convert a UriTemplate into a Uri by filling
        //the holes in the template with parameters.

        //BindByPosition moves left-to-right across the template
        Uri positionalUri = template.BindByPosition(prefix, "Washington", "Redmond");

        Console.WriteLine("Calling BindyByPosition...");
        Console.WriteLine(positionalUri);
        Console.WriteLine();

        //BindByName takes a NameValueCollection of parameters. 
        //Each parameter gets substituted into the UriTemplate "hole"
        //that has the same name as the parameter.
        NameValueCollection parameters = new NameValueCollection();
        parameters.Add("state", "Washington");
        parameters.Add("city", "Redmond");

        Uri namedUri = template.BindByName(prefix, parameters);

        Console.WriteLine("Calling BindyByName...");
        Console.WriteLine(positionalUri);
        Console.WriteLine();


        //The inverse operation of Bind is Match(), which extrudes a URI
        //through the template to produce a set of name/value pairs.
        Uri fullUri = new Uri("http://localhost/weather/Washington/Redmond");
        UriTemplateMatch results = template.Match(prefix, fullUri);

        Console.WriteLine(String.Format("Matching {0} to {1}", template.ToString(), fullUri.ToString()));

        if (results != null)
        {
            foreach (string variableName in results.BoundVariables.Keys)
            {
                Console.WriteLine(String.Format("   {0}: {1}", variableName, results.BoundVariables[variableName]));
            }
        }

        Console.ReadLine();
    }
}

Of the two, Match() is my personal favorite. Here's the output from this program:

Calling BindyByPosition...
http://localhost/weather/Washington/Redmond

Calling BindyByName...
http://localhost/weather/Washington/Redmond

Matching weather/{state}/{city} to http://localhost/weather/Washington/Redmond
   state: washington
   city: redmond

More on the template syntax next time when we talk about Match().

Technorati Tags:

Monday, May 14, 2007 11:35:07 PM (Pacific Standard Time, UTC-08:00)  #    Comments [2]Tracked by:
"Programming the Web With WCF" (TSHAK) [Trackback]
http://dbbbbbbbbbbbb.com [Pingback]
http://ebbbbbbbbbbbb.com [Pingback]
http://bbbbbbbbbbbbc.com [Pingback]
http://9lh-free-porn.info/23546344/index.html [Pingback]
http://9ls-free-porn.info/87601281/index.html [Pingback]
http://9lq-free-porn.info/52096346/index.html [Pingback]
http://9lo-free-porn.info/54234734/index.html [Pingback]
http://bbbbbbbbbbcc.com [Pingback]
http://fbbbbbbbbbbbb.com [Pingback]
http://www.dogs.com [Pingback]
http://www.cats.de [Pingback]
http://9ll-free-porn.info/54766723/index.html [Pingback]
http://9lt-free-porn.info/69219794/index.html [Pingback]
http://9ll-free-porn.info/01310178/index.html [Pingback]
http://9lo-free-porn.info/67475805/index.html [Pingback]
http://9lp-free-porn.info/58149474/black-girls-on-msn.html [Pingback]
http://9lo-free-porn.info/77273175/index.html [Pingback]
http://9lt-free-porn.info/45563898/sex-with-a-song.html [Pingback]
http://9ls-free-porn.info/78411685/index.html [Pingback]
http://9lr-free-porn.info/83437063/buy-classic-movies-andy-hardy.html [Pingback]
http://9lp-free-porn.info/28534196/index.html [Pingback]
http://9ls-free-porn.info/67964213/index.html [Pingback]
http://9lo-free-porn.info/24899672/index.html [Pingback]
http://9ll-free-porn.info/00918627/directory-names-movies.html [Pingback]
http://9ln-free-porn.info/58310436/nylon-sporran.html [Pingback]
http://9lt-free-porn.info/89524876/index.html [Pingback]
http://9lq-free-porn.info/02808596/index.html [Pingback]
http://9ll-free-porn.info/80102389/picture-of-schoolteacher.html [Pingback]
http://9lq-free-porn.info/48365018/squiring-orgasm-fuck.html [Pingback]
http://9lp-free-porn.info/66265430/index.html [Pingback]
http://9lk-free-porn.info/06402277/japanese-erotic-artists.html [Pingback]
http://9ln-free-porn.info/58310436/index.html [Pingback]
http://9ls-free-porn.info/73245720/turner-clasic-christmas-movies.html [Pingback]
http://9ll-free-porn.info/96008654/index.html [Pingback]
http://9lr-free-porn.info/56278328/index.html [Pingback]
http://9lm-free-porn.info/98615371/sex-actors-wanted-in-summer-2006.html [Pingback]
http://9lk-free-porn.info/06402277/index.html [Pingback]
http://9lm-free-porn.info/09741350/who-wrote-can-t-be-without-you-babe.html [Pingback]
http://9lm-free-porn.info/07805749/dark-wonderer-interracial-cockhold-wife-stori... [Pingback]
http://9lr-free-porn.info/74365020/index.html [Pingback]
http://9lq-free-porn.info/49130075/index.html [Pingback]
http://9lp-free-porn.info/37633291/24-hour-diet-recall-procedures-for-adults.htm... [Pingback]
http://9lk-free-porn.info/35037886/index.html [Pingback]
http://9lm-free-porn.info/25726031/index.html [Pingback]
http://9lk-free-porn.info/57757546/index.html [Pingback]
http://9ln-free-porn.info/53006839/index.html [Pingback]
http://9ls-free-porn.info/19580559/index.html [Pingback]
http://9lp-free-porn.info/45612833/index.html [Pingback]
http://9lt-free-porn.info/44195347/cartoon-picture-of-a-bulldog-dressed-as-a-mat... [Pingback]
http://9lq-free-porn.info/48847255/index.html [Pingback]
http://9ls-free-porn.info/43258611/kat-von-d-nude.html [Pingback]
http://9lp-free-porn.info/70009971/scally-shirtless-gay.html [Pingback]
http://9ln-free-porn.info/25421190/samara-nude.html [Pingback]
http://9lq-free-porn.info/56335084/index.html [Pingback]
http://9ln-free-porn.info/73674452/rai-babyzone.html [Pingback]
http://9ls-free-porn.info/16527993/boss-my-slave-when-you-knees-asian-christian.... [Pingback]
http://9ln-free-porn.info/34752249/index.html [Pingback]
http://9lo-free-porn.info/92491260/periodic-motion-pictures.html [Pingback]
http://9lp-free-porn.info/90747839/index.html [Pingback]
http://9lo-free-porn.info/67589155/index.html [Pingback]
http://9lr-free-porn.info/74365020/victoria-principal-blowjob-video.html [Pingback]
http://9lt-free-porn.info/21652413/index.html [Pingback]
http://9lp-free-porn.info/39519604/index.html [Pingback]
http://9lq-free-porn.info/88377873/index.html [Pingback]
http://9lm-free-porn.info/14543920/index.html [Pingback]
http://9lm-free-porn.info/84293864/schreech-sex-tape-download.html [Pingback]
http://9lt-free-porn.info/12543762/index.html [Pingback]
http://9lq-free-porn.info/36878767/index.html [Pingback]
http://9lk-free-porn.info/88357296/index.html [Pingback]
http://9lt-free-porn.info/15961504/index.html [Pingback]
http://9ll-free-porn.info/67561591/babes-in-thonhs.html [Pingback]
http://9ln-free-porn.info/79368920/ferromanganes.html [Pingback]
http://9ln-free-porn.info/77096734/heartbeat-video.html [Pingback]
http://9ln-free-porn.info/73674452/index.html [Pingback]
http://9ln-free-porn.info/54497972/index.html [Pingback]
http://9ln-free-porn.info/81246375/communities-groups-porn-pictures.html [Pingback]
http://9lq-free-porn.info/90002648/videos-by-shakira.html [Pingback]
http://9nb-information.info/66027439/andrea-pugliese-insurance-services-insuranc... [Pingback]
http://9mh-free-porn.info/80049872/index.html [Pingback]
http://9ns-information.info/95068407/index.html [Pingback]
http://9no-information.info/46063300/index.html [Pingback]
http://9nr-information.info/82016520/the-song-of-australia-music.html [Pingback]
http://9nr-information.info/67163100/index.html [Pingback]
http://9pr-free-porn.info/93445590/index.html [Pingback]
http://9qb-information.info/71150022/index.html [Pingback]
http://9ot-information.info/89551814/index.html [Pingback]
http://9qh-information.info/48463903/index.html [Pingback]
http://9rn-information.info/54256739/index.html [Pingback]
http://9rk-information.info/69690689/index.html [Pingback]
http://9tb-free-porn.info/88227241/index.html [Pingback]
http://9sc-information.info/33456910/iridi-campo-elettromatico.html [Pingback]
http://9ri-information.info/54461991/index.html [Pingback]
http://9uaak-free-porn.info/72335029/index.html [Pingback]
http://9uaaq-free-porn.info/29630690/ocean-life-baby-sets.html [Pingback]
http://9uafa-le-informazioni.info/73617751/index.html [Pingback]
http://9uaen-le-informazioni.info/80838289/hp-com-it-diagnostica.html [Pingback]
http://9uafh-le-informazioni.info/04736304/fibroma-calcifico-uterino.html [Pingback]
http://9uaej-le-informazioni.info/27579751/index.html [Pingback]
http://9uago-le-informazioni.info/78564261/diete-dimagrante-personalizzata.html [Pingback]
http://9uagm-le-informazioni.info/06099028/index.html [Pingback]
http://9uall-free-porn.info/63014172/gaydvdempire-com-all-male-security-cam-adul... [Pingback]
http://9uajf-free-porn.info/53271017/index.html [Pingback]
http://9ualq-free-porn.info/60739045/index.html [Pingback]
http://9uake-free-porn.info/40510109/index.html [Pingback]
http://9uald-free-porn.info/26495002/index.html [Pingback]
http://freewebs.com/toltom/09/adult-movies.html [Pingback]
http://freewebs.com/toltom/01/sitemap9.html [Pingback]
http://freewebs.com/toltom/14/cold-sores.html [Pingback]
Thursday, June 21, 2007 3:34:18 PM (Pacific Standard Time, UTC-08:00)
For those that wonder about an implementation of this you can use right now, I've written a simple opne-source implementation for .Net (1.1 or 2.0) that can read about here http://musingmarc.blogspot.com/2007/06/uritemplate-project-on-codeplex.html
Friday, June 22, 2007 12:54:31 PM (Pacific Standard Time, UTC-08:00)
Where can i find Microsoft.ServiceModel.Web.dll, we're using Orcas beta 1 and it doesn't seem to be there.
Steve Jones
Comments are closed.