Пример #1
0
        object ReadResponse(HttpClientMethod method, WebResponse response, Stream responseStream)
        {
            HttpWebResponse httpResponse = response as HttpWebResponse;

            if (httpResponse != null && (int)httpResponse.StatusCode >= 300)
            {
                throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null,
                                       WebExceptionStatus.ProtocolError, httpResponse);
            }

            if (method.readerType == null)
            {
                return(null);
            }

            // CONSIDER,yannc: in future versions when we allow additional mime formatters we
            //      : should consider giving them access to the response even if there is no
            //      : response content.
            if (responseStream != null)
            {
                MimeReturnReader reader = (MimeReturnReader)MimeFormatter.CreateInstance(method.readerType, method.readerInitializer);
                return(reader.Read(response, responseStream));
            }
            else
            {
                return(null);
            }
        }
        object ReadResponse(HttpClientMethod method, WebResponse response, Stream responseStream)
        {
            HttpWebResponse httpResponse = response as HttpWebResponse;

            if (httpResponse != null && (int)httpResponse.StatusCode >= 300)
            {
                throw new WebException(RequestResponseUtils.CreateResponseExceptionString(httpResponse, responseStream), null,
                                       WebExceptionStatus.ProtocolError, httpResponse);
            }

            if (method.readerType == null)
            {
                return(null);
            }

            //


            if (responseStream != null)
            {
                MimeReturnReader reader = (MimeReturnReader)MimeFormatter.CreateInstance(method.readerType, method.readerInitializer);
                return(reader.Read(response, responseStream));
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        void AsyncGetResponseDone(IAsyncResult ar)
        {
            SimpleWebClientAsyncResult ainfo = (SimpleWebClientAsyncResult)ar.AsyncState;
            WebResponse response             = null;

            try {
                response = GetWebResponse(ainfo.Request, ar);
            }
            catch (WebException ex) {
                response = ex.Response;
                HttpWebResponse http_response = response as HttpWebResponse;
                if (http_response == null || http_response.StatusCode != HttpStatusCode.InternalServerError)
                {
                    ainfo.SetCompleted(null, ex, true);
                    return;
                }
            }
            catch (Exception ex) {
                ainfo.SetCompleted(null, ex, true);
                return;
            }

            try {
                MimeReturnReader returnReader = (MimeReturnReader)ainfo.Method.ReturnReaderType.Create();
                object           result       = returnReader.Read(response, response.GetResponseStream());
                ainfo.SetCompleted(result, null, true);
            }
            catch (Exception ex) {
                ainfo.SetCompleted(null, ex, true);
            }
        }
Пример #4
0
        private object ReadResponse(HttpClientMethod method, WebResponse response, Stream responseStream)
        {
            HttpWebResponse response2 = response as HttpWebResponse;

            if ((response2 != null) && (response2.StatusCode >= HttpStatusCode.MultipleChoices))
            {
                throw new WebException(RequestResponseUtils.CreateResponseExceptionString(response2, responseStream), null, WebExceptionStatus.ProtocolError, response2);
            }
            if ((method.readerType != null) && (responseStream != null))
            {
                MimeReturnReader reader = (MimeReturnReader)MimeFormatter.CreateInstance(method.readerType, method.readerInitializer);
                return(reader.Read(response, responseStream));
            }
            return(null);
        }
Пример #5
0
        protected object Invoke(string methodName, string requestUrl, object[] parameters)
        {
            HttpSimpleMethodStubInfo method          = (HttpSimpleMethodStubInfo)TypeStub.GetMethod(methodName);
            MimeParameterWriter      parameterWriter = (MimeParameterWriter)method.ParameterWriterType.Create();

            string     url     = parameterWriter.GetRequestUrl(requestUrl, parameters);
            WebRequest request = GetWebRequest(new Uri(url, true));

            parameterWriter.InitializeRequest(request, parameters);

            if (parameterWriter.UsesWriteRequest)
            {
                Stream stream = request.GetRequestStream();
                parameterWriter.WriteRequest(stream, parameters);
                stream.Close();
            }

            WebResponse response = GetWebResponse(request);

            MimeReturnReader returnReader = (MimeReturnReader)method.ReturnReaderType.Create();

            return(returnReader.Read(response, response.GetResponseStream()));
        }