[OperationContract]
[WebGet]
public string HelloWorld()
{
var properties = OperationContext.Current.IncomingMessageProperties;
var property = properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
string queryString = property.QueryString;
var name = StringUtils.GetUrlEncodedKey(queryString,"Name");
return "Hello World " + name;
}
And that doesn’t account for the logic in GetUrlEncodedKey to retrieve the querystring value.
It’s a heck of a lot easier to just do this:
[OperationContract]
[WebGet]
public string HelloWorld()
{
var name = HttpContext.Current.Request.QueryString["Name"] ?? string.Empty;
return "Hello World " + name;
}
Ok, so if you follow the REST guidelines for WCF REST you shouldn’t have to rely on reading query string parameters manually but instead rely on routing logic, but you know what: WCF REST is a PITA anyway and anything to make things a little easier is welcome.
Read more: Rick Strahl's blog