示例#1
0
        private static async Task <ServiceDesc> ParseServiceDescription(HttpRequest request)
        {
            var reader = new StreamReader(request.Body);

            try
            {
                var serviceDesc = new ServiceDesc();
                var ctx         = new ParseContext(reader, serviceDesc);

                while (!reader.EndOfStream)
                {
                    await ParseServiceDescPipeline.Invoke(ctx);
                }

                return(serviceDesc);
            }
            catch (Exception ex)
            {
                throw new BadRequestException("Unable to parse service description.", ex);
            }
            finally
            {
                ((IDisposable)reader).Dispose();
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new service using the specified service description. See
        /// the ServiceDesc class for more information.
        /// </summary>
        public Service(ServiceDesc desc)
        {
            RequiresArgument.NotNullOrWhiteSpace(desc.Method, "Method");
            RequiresArgument.NotNullOrWhiteSpace(desc.Path, "Path");
            RequiresArgument.NotNullOrWhiteSpace(desc.ContentType, "ContentType");
            RequiresArgument.NotNullOrWhiteSpace(desc.StatusCode, "StatusCode");
            RequiresArgument.NotNull(desc.Body, "Body");

            thisLock = new object();
            Id       = ParseId(desc.Id);
            // The method and path values are use for string matching, so
            //convert them to upper invariant.
            method     = desc.Method.ToUpperInvariant();
            path       = desc.Path.ToUpperInvariant();
            bodyFilter = desc.BodyContains;
            response   = new ServiceResponse()
            {
                Body        = desc.Body,
                ContentType = desc.ContentType,
                StatusCode  = ParseStatusCode(desc.StatusCode)
            };
            callCount       = 0;
            lastRequestBody = string.Empty;
        }