0

I am building a wcf rest service to upload a file

[WebInvoke(Method = "POST", UriTemplate = "upload?fileName={fileName}&filePath={filePath}&replace={replace}")]
    void UploadFile(Stream fileContent, string fileName, string filePath, bool replace);

Here I need to make filePath & replace parameter as optional. I can not simply rely on null check i.e. filePath = filePath ?? "" inside method if consumer doesn't pass the value for the parameter because first of all consumer doesn't know whether the parameters are required or optional. any help?

Binod Mahto
  • 340
  • 2
  • 13
  • have you tried to set a default value of null? like this: `upload?fileName={fileName}&filePath={filePath=null}&replace={replace=null}"` ? – Ricardo Pontual Oct 11 '16 at 11:13
  • yes I tried and got exception saying "the UriTemplate variable declaration 'filePath=null' provides a default value to query variable 'filePath'. Note that UriTemplate doesn't support default values to query variables. " – Binod Mahto Oct 11 '16 at 12:21
  • A similar question was asked [here](http://stackoverflow.com/questions/17251719/optional-parameter-in-uritemplate-in-wcf). see if it solves your problem – Parag Patil Oct 11 '16 at 16:33
  • Didn't quite understand why you can't just do a simple `UriTemplate = "upload?fileName={fileName}&filePath={filePath}&replace={replace}"` and then check for null in the method body. Can you please elaborate further – Parag Patil Oct 11 '16 at 17:05
  • yeah I can but that won't tell consumer about the parameters nature (optional or required). By the way I feel better to have multiple endpoint here. – Binod Mahto Oct 12 '16 at 03:42

0 Answers0