.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

WCF UriTemplate

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :WCF

How can I read the method parameters to create a NameValueCollection for the UriTemplate. I have been trying to create a REST client for my WCF service. It seems that if I want custom handling of return HTTPstatus codes (aka dont lose the returning payload) that I should write my own client. :(

so lets say that my method is

void Foo(string param1, string param2, int last)


   UriTemplate temp = new UriTemplate(_host + "/register?id1={param1}?id2={param2}?id3={last}");

   // create collection of params ?? How?

   NameValueCollection col;

   temp.BindByName(_uri, col);


View Complete Post

More Related Resource Links

WCF URITemplate for generic query



I'm writing a proxy and I want to implement a WebGET URITemplate that will allow me to grab the entire set of name/value pairs as a single entity.  ie calling


I want a string that is "p1=1&p2=2" or "?p1=1&p2=2"

I've tried various URITemplates with no success. 

URITemplate="{request}" works for http://myproxy/p1=1&p2=2 but not with the preceding "?"

URITemplate="*" passes through to my associated function (for which I cannot in this case specify a parameter and which I can't see how to retrieve)

URITemplate="*{request}" or "?{request}" are invalid

Any ideas?  Basically, it seems you need to indicate the ? and then you must go the name/value pair route but I won't know what these are in advance

URITemplate Inconsistency... QueryStrings Parameters Sometimes Null - Sometimes Not...

Hello all,

I've encountered a strange inconsistecy in the way WCF parses URIs?

My contract looks like:

    <OperationContract()> _
    <WebGet(UriTemplate:="{CampaignID}/objects?page={Page}&pagesize={PageSize}")> _
    Sub getObjects(ByVal CampaignID As String, ByVal Page As String, ByVal PageSize As String)

    <OperationContract()> _
    <WebInvoke(Method:="POST", UriTemplate:="{CampaignID}/objects")> _
    Sub addObject(ByVal CampaignID As String)

getObjects cannot be run without parameters - in this case, it'll return "Method Not Allowed".

However - if addObject is removed ... getObjects CAN run without parameters (Null will be passed in for Page/PageSize).

Why is there an inconsistency in the way WCF processes query string parameters - is there a way to fix this inconsistency... i

One URITemplate for More Than One Method



I am new on REST and want to build some flexible RESTful WCF Services.

I want to use my base address as the URITemplate for all of method define in that .svc file.

But it is not allowing me to get the same URi for more than one method.

Is it the condition that we have to use the unique URi fro each and every Method.

I am Passing different parameter in the all method so it should Identify at one URL.


Kumar Gaurav

UriTemplate won't match string parameters with slashes


Hello All,

I have a WCF service that takes string parameters in the UriTemplate which contain slashes. For example, I want to setup a UriTemplate like "/items/{itemId}/elements", where the itemId contains slashes.

I tried to use the wildcard, like  "/items/{*itemId}/elements, but using this template chokes the runtime. I learned from this link that it appears to work only when the wildcard appears in last variable is the segment.

I could remove the offending variable (in this case, itemId) from the Uri and add it to the body of the request, but I woul like to avoid it since it would result URLs not very intuitive.

Any help would be greatly appreciated.

Kind regards





WCF UriTemplate and POST data


I am building a set of RESTful web services with WCF. I am trying to figure out how to combine the URITemplate with data being posted in the web call. 

This is the service contract section of one the methods I would like to expose:

[WebInvoke(Method = "POST", UriTemplate = "/{itemid}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
MyResponse doit(string itemid);

The URiTemplate resolver gives me the itemid parameter but how can I access the data being POSTed ?  


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend