DataServiceRequest<TElement> Class
Represents request objects submitted as a batch to the data service.
System.Data.Services.Client::DataServiceRequest
System.Data.Services.Client::DataServiceRequest<TElement>
Assembly: System.Data.Services.Client (in System.Data.Services.Client.dll)
The DataServiceRequest<TElement> type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DataServiceRequest<TElement> | Initializes a new instance of the DataServiceRequest<TElement> class. |
| Name | Description | |
|---|---|---|
![]() | ElementType | Gets the type of the object used to create the DataServiceRequest<TElement> instance. (Overrides DataServiceRequest::ElementType.) |
![]() | RequestUri | Gets the URI object that contains the request string. (Overrides DataServiceRequest::RequestUri.) |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | 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
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.
}
}
}
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.
