Export (0) Print
Expand All

DataServiceRequest<TElement> Class

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

System.Object
  System.Data.Services.Client.DataServiceRequest
    System.Data.Services.Client.DataServiceRequest<TElement>

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

public sealed class DataServiceRequest<TElement> : DataServiceRequest

Type Parameters

TElement

The DataServiceRequest<TElement> type exposes the following members.

  NameDescription
Public methodDataServiceRequest<TElement>Initializes a new instance of the DataServiceRequest<TElement> class.
Top

  NameDescription
Public propertyElementTypeGets the type of the object used to create the DataServiceRequest<TElement> instance. (Overrides DataServiceRequest.ElementType.)
Public propertyRequestUriGets the URI object that contains the request string. (Overrides DataServiceRequest.RequestUri.)
Top

  NameDescription
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 a hash function for a particular type. (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 methodToStringRepresents the URI of the query to the data service. (Inherited from DataServiceRequest.)
Top

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 
                                                    Uri("http://myserviceroot"));

// 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;
try
{
    // 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.  */
            }
        }
        else
        {
            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

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.

Community Additions

ADD
Show:
© 2014 Microsoft