1

What I am looking for is a way I can pass anything to a specific url so I can parse it myself. Something like this :

    [OperationContract]
    [WebGet(UriTemplate = "/whatever/blabla/{query}", RequestFormat = WebMessageFormat.Xml)]
    string AddRouteForUser(string query);

Afterwards I can parse query myself to have the values I need. Is it possible ? Is there a better way ?

Thanks

[Edit title]

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
lollancf37
  • 1,105
  • 3
  • 15
  • 27
  • 1
    Not to have, How to have... spellcheck must have been optional – H H Sep 21 '11 at 10:15
  • Someone has started a new thread http://stackoverflow.com/questions/12246168/optional-query-string-parameter-passing-to-wcf-service/39110185#39110185 and share the views with you. I have put my answer over there before I realized this one – Jenna Leaf Aug 23 '16 at 21:17

2 Answers2

4

One option would be to use query string params since by definition, they're sort of an optional property bag of options tagged onto a query. That leaves the path to being an immutable identifier for your rest resource.

/whatever/blabla?some=data&whichis=optional

It's hard to say though without sepcific knowledge of the data and the rest resources

EDIT:

QueryStrings can be optional.
See comment from Anand @ https://connect.microsoft.com/VisualStudio/feedback/details/451296/rest-wcf-uritemplate-optional-querystring-parameters

"You can get the desired effect by omitting the Query string from the UriTemplate on your WebGet or WebInvoke attribute, and using WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters"

bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • I didn't really get that one.Does that force me to hard code all possibilities ? – lollancf37 Sep 21 '11 at 11:55
  • Edited more info to answer your question - it's saying you can omit the QA and it's optional. If you have both a get and invoke on it, then the workaround is the QueryParameters method above. – bryanmac Sep 21 '11 at 18:15
  • Sweet it's much simpler than what I was doing with OperationContext. Thank you ! – lollancf37 Sep 22 '11 at 08:14
  • It would only allow the parameters to be optional for me if the query string was without trailing slash. With it, it wouldn't work. You'll have to change the UriTemplate as well for that to work. – Wotuu May 30 '13 at 11:28
0

At the end I am going to use OperationContext to get the complete url and parse it myself. I just put in WebGet this /whatever/{query} so I know what I want to treat.

lollancf37
  • 1,105
  • 3
  • 15
  • 27