I just tested it with WCF 4 and it worked without problems. If I do not use the mode in the query string, I will get null as the parameter value:
[ServiceContract] public interface IService { [OperationContract] [WebGet(UriTemplate = "GetData?data={value}&mode={mode}")] string GetData(string value, string mode); }
Method implementation:
public class Service : IService { public string GetData(string value, string mode) { return "Hello World " + value + " " + mode ?? ""; } }
For me, it looks like all query string parameters are optional. If the parameter is not present in the query string, it will have a default value for its type => null for string , 0 for int , etc. MS also states that this should be implemented.
In any case, you can always define a UriTemplate using id , type and language and access the optional parameters inside the WebOperationContext method:
var mode = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["mode"];
Ladislav Mrnka Apr 25 2018-11-18T00: 00Z
source share