private ShimWebResponse CallDispatcher(InterceptDispatcher dispatcher, WebRequest request, MemoryStream requestStream)
        {
            ShimWebResponse response = null;

            _lastUsedDispatcher = dispatcher;

            Stopwatch timer = new Stopwatch();

            timer.Start();

            try
            {
                using (var context = new ShimCallContext(request, requestStream))
                {
                    if (StringComparer.OrdinalIgnoreCase.Equals(request.Method, "POST") && requestStream != null)
                    {
                        // convert the batched call into a regular url
                        context.UnBatch();
                    }

                    V3InteropTraceSources.ShimController.Verbose("dispatching", "Dispatching {0} {1}", request.Method, request.RequestUri.AbsoluteUri);

                    var t = Task.Run(async() => await dispatcher.Invoke(context));
                    t.Wait();

                    var stream = context.Data;

                    timer.Stop();

                    V3InteropTraceSources.ShimController.Verbose("dispatched", "Dispatched {0} {1} in {2}ms", request.Method, request.RequestUri.AbsoluteUri, timer.ElapsedMilliseconds);

                    response = new ShimWebResponse(stream, request.RequestUri, context.ResponseContentType, context.StatusCode);
                }
            }
            catch (AggregateException ex)
            {
                // unwrap the exception to get a useful error
                var innerException = ExceptionUtility.Unwrap(ex);

                // TODO: throw a DataServiceQueryException with the correct xml
                throw innerException;
            }

            return(response);
        }
Ejemplo n.º 2
0
        private ShimWebResponse CallDispatcher(InterceptDispatcher dispatcher, WebRequest request, MemoryStream requestStream)
        {
            ShimWebResponse response = null;
            _lastUsedDispatcher = dispatcher;

            Stopwatch timer = new Stopwatch();
            timer.Start();

            try
            {
                using (var context = new ShimCallContext(request, requestStream))
                {
                    if (StringComparer.OrdinalIgnoreCase.Equals(request.Method, "POST") && requestStream != null)
                    {
                        // convert the batched call into a regular url
                        context.UnBatch();
                    }

                    V3InteropTraceSources.ShimController.Verbose("dispatching", "Dispatching {0} {1}", request.Method, request.RequestUri.AbsoluteUri);

                    var t = Task.Run(async () => await dispatcher.Invoke(context));
                    t.Wait();

                    var stream = context.Data;

                    timer.Stop();

                    V3InteropTraceSources.ShimController.Verbose("dispatched", "Dispatched {0} {1} in {2}ms", request.Method, request.RequestUri.AbsoluteUri, timer.ElapsedMilliseconds);

                    response = new ShimWebResponse(stream, request.RequestUri, context.ResponseContentType, context.StatusCode);
                }
            }
            catch (AggregateException ex)
            {
                // unwrap the exception to get a useful error
                var innerException = ExceptionUtility.Unwrap(ex);

                // TODO: throw a DataServiceQueryException with the correct xml
                throw innerException;
            }

            return response;
        }