Duration (Pacific Standard Time):
To (Pacific Standard Time):
  • None
User Action:
  • None

DataServiceRequest<TElement> Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Represents request objects submitted as a batch to the data service.

Namespace:   System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)


Public NotInheritable Class DataServiceRequest(Of TElement)
	Inherits DataServiceRequest
Name Description
System_CAPS_pubmethod DataServiceRequest<TElement>(Uri)

Initializes a new instance of the DataServiceRequest<TElement> class.

Name Description
System_CAPS_pubproperty ElementType

Gets the type of the object used to create the DataServiceRequest<TElement> instance.(Overrides DataServiceRequest.ElementType.)

System_CAPS_pubproperty RequestUri

Gets the URI object that contains the request string. (Overrides DataServiceRequest.RequestUri.)

Name Description
System_CAPS_pubmethod Equals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod ToString()

Represents the URI of the query to the data service. (Inherited from DataServiceRequest.)

In a group of queries submitted as a batch to the data service, the queries are specified as DataServiceRequest<TElement> instances. A DataServiceResponse is returned that represents the response of the batch request as a whole. Individual query responses are represented as QueryOperationResponse objects, derived from OperationResponse, that are accessible by enumerating the DataServiceResponse instance.

When ExecuteBatch returns, the entire HTTP response for the batch request has been read from the network stream, but the responses have not been processed. Identity resolution and object materialization do not occur for a specified entity in the response until it is iterated as shown in the following example.

DataServiceContext service = new DataServiceContext(new 

// Create query batches.
DataServiceRequest[] reqs = new DataServiceRequest[] { 
    new DataServiceRequest<Category>(
            new Uri("http://myserviceroot/Categories")),
            new DataServiceRequest<Customer>(
            new Uri("http://myserviceroot/Customers"))

DataServiceResponse dsr;
    // Client will not throw an exception on ExecuteBatch because the 
    // entire response has not been processed yet to know
    // whether an exception should be thrown.

    dsr = service.ExecuteBatch(reqs);   

    if (dsr.IsBatchResponse) 
        /*inspect HTTP artifacts associated with the entire batch:
                      dsr.BatchHeaders, dsr.BatchStatusCode*/ }

    foreach (QueryOperationResponse qr in dsr)
        if (IsErrorStatusCode(qr.StatusCode))   
            //q.Error.Message contains the full contents of the error.
            /* process any part of the Error Contract (<error> element)
                      sent from the service.  */
            if (qr.Query.ElementType == typeof(Customer))
                //process customers
                foreach (Customer c in qr){ /*process the customer*/ }

                // the DataServiceContext does not materialize, resolve
                // identity on Customer until it is enumerated.
            else if (qr.Query.ElementType == typeof(Category))
                // Process categories.
                foreach (Category cat in qr)
                    /*process the category*/ 
                // the DataServiceContext does not materialize or
                // resolve identity on the Category until
                // it is enumerated.
                // This means that instream errors will be thrown
                // during iteration.
catch (DataServiceRequestException e)
    // This error is thrown if the data service returns with
    // a response code < 200 or >299 or the top level element.
    // If neither of the above or true, this exception is not 
    // thrown.

    dsr = e.Response;

    if (dsr.IsBatchResponse) 
        /*inspect HTTP artifacts associated with the entire batch:
                        dsr.BatchHeaders, dsr.BatchStatusCode*/ 

    /* There will always only be one of these because if the top level
     status code was >=200 and =<299 and the first element was not an
     error, the call to start the query will not throw. */

    foreach (QueryOperationResponse qr in dsr)
        if (qr.Error != null)
            // Process error.

.NET Framework
Available since 3.5
Available since 2.0

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

Return to top