I just started using WCF with REST and UriTemplates. Is it now possible to use optional parameters?
If not, what would you guys recommend I do for a system that has three parameters that are always used in the url, and others that are optional (varying amount)?
Example:
https://example.com/?id=ID&type=GameID&language=LanguageCode&mode=free
- id, type, language are always present
- mode is optional
I just tested it with WCF 4 and it worked without any problems. If I don’t use mode in query string I will get null as parameter’s value:
Method implementation:
For me it looks like all query string parameters are optional. If a parameter is not present in query string it will have default value for its type =>
nullforstring, 0 forint, etc. MS also states that this should be implemented.Anyway you can always define
UriTemplatewithid,typeandlanguageand access optional parameters inside method byWebOperationContext: