Esempio n. 1
0
        internal override object[] ReadParameters()
        {
            if (serverMethod.readerTypes == null)
            {
                return(new object[0]);
            }
            for (int i = 0; i < serverMethod.readerTypes.Length; i++)
            {
                if (!hasInputPayload)
                {
                    // only allow URL parameters if doesn't have payload
                    if (serverMethod.readerTypes[i] != typeof(UrlParameterReader))
                    {
                        continue;
                    }
                }
                else
                {
                    // don't allow URL params if has payload
                    if (serverMethod.readerTypes[i] == typeof(UrlParameterReader))
                    {
                        continue;
                    }
                }
                MimeParameterReader reader = (MimeParameterReader)MimeFormatter.CreateInstance(serverMethod.readerTypes[i],
                                                                                               serverMethod.readerInitializers[i]);

                object[] parameters = reader.Read(Request);
                if (parameters != null)
                {
                    return(parameters);
                }
            }
            if (!hasInputPayload)
            {
                throw new InvalidOperationException(Res.GetString(Res.WebInvalidRequestFormat));
            }
            else
            {
                throw new InvalidOperationException(Res.GetString(Res.WebInvalidRequestFormatDetails, Request.ContentType));
            }
        }
Esempio n. 2
0
        public override void ProcessRequest(HttpContext context)
        {
            Context = context;
            Stream    respStream = null;
            Exception error      = null;

            try
            {
                if (method == null)
                {
                    method = (HttpSimpleMethodStubInfo)GetRequestMethod(context);
                }

                if (method.MethodInfo.EnableSession)
                {
                    Session = context.Session;
                }

                MimeParameterReader parameterReader = (MimeParameterReader)method.ParameterReaderType.Create();
                object[]            parameters      = parameterReader.Read(context.Request);

                MimeReturnWriter returnWriter = (MimeReturnWriter)method.ReturnWriterType.Create();
                object           result       = Invoke(method.MethodInfo, parameters);
                respStream = context.Response.OutputStream;
                returnWriter.Write(context.Response, respStream, result);
            }
            catch (Exception ex)
            {
                error = ex;
            }

            if (error != null)
            {
                WriteError(context, error.ToString());
            }

            if (respStream != null)
            {
                respStream.Close();
            }
        }