DataServiceRequest<TElement> Класс

Определение

Представляет объекты запроса, переданные в виде пакета службе данных.

generic <typename TElement>
public ref class DataServiceRequest sealed : System::Data::Services::Client::DataServiceRequest
public sealed class DataServiceRequest<TElement> : System.Data.Services.Client.DataServiceRequest
type DataServiceRequest<'Element> = class
    inherit DataServiceRequest
Public NotInheritable Class DataServiceRequest(Of TElement)
Inherits DataServiceRequest

Параметры типа

TElement
Наследование
DataServiceRequest<TElement>

Примеры

При ExecuteBatch возврате весь HTTP-ответ для пакетного запроса был считан из сетевого потока, но ответы не были обработаны. Разрешение удостоверений и материализация объектов не выполняются для указанной сущности в ответе, пока она не будет итерирована, как показано в следующем примере.

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.
        }
    }
}

Комментарии

В группе запросов, отправленных в службу данных в виде пакета, запросы указываются как DataServiceRequest<TElement> экземпляры. DataServiceResponse Возвращается объект , представляющий ответ на пакетный запрос в целом. Отдельные ответы на запросы представлены в виде QueryOperationResponse объектов, производных от OperationResponse, которые доступны путем перечисления экземпляра DataServiceResponse .

Конструкторы

Имя Описание
DataServiceRequest<TElement>(Uri)

Инициализирует новый экземпляр класса DataServiceRequest<TElement>.

Свойства

Имя Описание
ElementType

Возвращает тип объекта, использованного для создания экземпляра DataServiceRequest<TElement>.

RequestUri

Возвращает объект URI, содержащий строку запроса.

Методы

Имя Описание
Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает объект Type для текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неполную копию текущего объекта Object.

(Унаследовано от Object)
ToString()

Представляет URI запроса к службе данных.

(Унаследовано от DataServiceRequest)

Применяется к