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:
[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 a parameter is not present in query string it will have default value for its type => null
for string
, 0 for int
, etc. MS also states that this should be implemented.
Anyway you can always define UriTemplate
with id
, type
and language
and access optional parameters inside method by WebOperationContext
:
var mode = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["mode"];