MIX07 - WCF adding System.UriTemplate, [WebGet], and [WebInvoke] - Jon Galloway

MIX07 - WCF adding System.UriTemplate, [WebGet], and [WebInvoke]

System.UriTemplate

Build and parse URI's

System.UriTemplate (Orcas) - runtime support for URI template syntax
UriTemplate.Bind - A safe, smart string.format for URI construction
UriTemplate.Match - Extracts URI to dictionary
UriTemplateTable - One or more template, best match wins

HTTP GET - bound semantics, expectation of idempotency, generally "safe" Chaos - HTTP POST, PUT, DELETE, others


WebHttpClient client = new WebHttpClient()
{
  UriTemplate = "http://localhost/mix/data/symbols{0}";
}
MixData = client.Get(StockSymbol).GetBody();
return data;

WCF adds [WebGet] and [WebInvoke]


[OperationContract]
[WebGet( UriTemplate = "data/symbols/{symbol}")]
public MixData GetCurrentData(int index)
{
  MixLogic logic = new MixLogic();
  return logic.GetData();
}

[OperationContract]
[WebGet( UriTemplate = "data/results/{index}")]
public MixData GetCachedResults(string index)
{
int i = int.Parse(index);
if(i >= IMDB.Conptents.Length)
{
  // Not found logic;
}
[OperationContract]
[WebGet ( UriTemplate = "data/feeds/{format}" )]
public object GetFeeds(string format)
{
  int i = 0;
  syndicationFeed feed = new SyndicationFeed (Mix Data", "some results",
  new Uri ("http://microsoft.com"),
  from data in IMDB.contents
  select new SyndicationItem (data.StockSymbol, data.Price, etc.)...
}

There was cooler code which consumes an RSS feed as well

XML, JSON, or opaque binary formats (V1 already included SOAP and POX

SyndicationFeed / SyndicationItem provide rich programming model for dealing with RSS / ATOM

In Orcas:

  • UriTemplate
  • [WebGet]
  • SyndicationFeed
  • LINQ fro XML
  • JSON formatter

WebHttpClient is speculative, not in Orcas

Published Wednesday, May 02, 2007 10:49 AM by Jon Galloway
Filed under: , , ,

Comments

# re: MIX07 - WCF adding System.UriTemplate, [WebGet], and [WebInvoke]

Ohh I have VS 2k8 on Windows server 2k3 ent. but when i start new project in Visual Web Developer 'WCF Service' and add WebGet attribute into the contract it's don't work!

[OperationContract]

[WebGet(UriTemplate = "GetData/{value}")]

string GetData(int value);

and I try to write into URI : localhost/.../2

but it's don't work. why I used the template project without any change just I added the new attribute. where is the problem ?

Thursday, May 01, 2008 3:26 AM by Haytham

# re: MIX07 - WCF adding System.UriTemplate, [WebGet], and [WebInvoke]

Haytham it has to be a string in your GetData(string value)

for it to work

One important limitation with UriTemplate to keep in mind that parameter mapping ( inside of {} ) only works with string parameters, so even simple type mapping like int, bool, or dates don’t work with them.

Wednesday, December 17, 2008 4:42 PM by Taswar

# Url Rewriting

One of my interesting is "URL Rewriting". The first time I have implemented it through implementing

Tuesday, December 23, 2008 1:21 PM by Journal of Abu Sayed Mohammad Ismail

# Url Rewriting using WCF

One of my interesting thing is "URL Rewriting". The first time I have implemented it through

Tuesday, December 23, 2008 1:32 PM by Journal of Abu Sayed Mohammad Ismail

Leave a Comment

(required) 
(required) 
(optional)
(required)