Export (0) Print
Expand All

QueryStringConverter Class

This class converts a parameter in a query string to an object of the appropriate type. It can also convert a parameter from an object to its query string representation.

System.Object
  System.ServiceModel.Dispatcher.QueryStringConverter
    System.ServiceModel.Dispatcher.JsonQueryStringConverter

Namespace:  System.ServiceModel.Dispatcher
Assembly:  System.ServiceModel.Web (in System.ServiceModel.Web.dll)

public class QueryStringConverter

The QueryStringConverter type exposes the following members.

  NameDescription
Public methodQueryStringConverterInitializes a new instance of the QueryStringConverter class.
Top

  NameDescription
Public methodCanConvertDetermines whether the specified type can be converted to and from a string representation.
Public methodConvertStringToValueConverts a query string parameter to the specified type.
Public methodConvertValueToStringConverts a parameter to a query string representation.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Parameters can be specified in a query string within a URL. This class takes those parameters specified in a string and converts them into objects. For example, the following contract is defined.

[ServiceContract]
interface Calculator
{
   [WebGet(UriTemplate="Add?n1={n1}&n2={n2}")]
   [OperationContract]
   long Add(long n1, long n2);
}

A Windows Communication Foundation (WCF) service implements this interface and exposes it on an endpoint with the WebHttpBehavior at http://localhost:8000/MyCalcService. The Add service operation can be called by sending an HTTP GET to http://localhost:8000/MyCalcService/Add?n1=10&n2=5. The QueryStringConverter receives this URL and converts the two parameters (n1 and n2) specified in the URL into two long objects with the appropriate values.

You can derive a class from QueryStringConverter to control how query string parameters are mapped into a service operation's parameters.

The QueryStringConverter supports the following types by default:

The following code shows how to use the QueryStringConverter class to convert between a string and a 32-bit integer.

QueryStringConverter converter = new QueryStringConverter();
if (converter.CanConvert(typeof(Int32)))
    converter.ConvertStringToValue("123", typeof(Int32));
int value = 321;
string strValue = converter.ConvertValueToString(value, typeof(Int32));
Console.WriteLine("the value = {0}, the string representation of the value = {1}", value, strValue);

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft