Esempio n. 1
0
        static public Response Send(
            string url,
            string method,
            string[] headers,
            byte[] body,
            Options options
            )
        {
            var uuid = System.Guid.NewGuid().ToString();
            var resp = new ResponseImpl(uuid);

            respmap_[uuid] = resp;
            sbyte[] sbody = null;
            if (body != null)
            {
                // this wasteful code to prevent warning:
                // AndroidJNIHelper.GetSignature: using Byte parameters is obsolete, use SByte parameters instead
                sbody = new sbyte[body.Length];
                Buffer.BlockCopy(body, 0, sbody, 0, body.Length);
            }
            client_.Call <string>("execute", uuid, url, method, headers, sbody,
                                  options != null ? options.filepath : null
                                  );
            return(resp);
        }
Esempio n. 2
0
        private void OnGetResponseCompleted(IAsyncResult ar)
        {
            var asyncResult = ar.AsyncState as HttpAsyncResult;

            Debug.Assert(asyncResult != null && asyncResult.WebRequest != null);

            try
            {
                var             response = asyncResult.WebRequest.EndGetResponse(ar) as HttpWebResponse;
                ServiceResponse res      = new ResponseImpl(response);
                HandleResponse(res, asyncResult.Context.ResponseHandlers);
                asyncResult.Complete(res);
            }
            catch (WebException we)
            {
                try
                {
                    var res = HandleException(we);
                    HandleResponse(res, asyncResult.Context.ResponseHandlers);
                    asyncResult.WebRequest.Abort();
                    asyncResult.Complete(res);
                }
                catch (Exception ie)
                {
                    asyncResult.WebRequest.Abort();
                    asyncResult.Complete(ie);
                }
            }
            catch (Exception oe)
            {
                asyncResult.WebRequest.Abort();
                asyncResult.Complete(oe);
            }
        }
 public HttpListenerContextImpl(HttpListenerContext context, HttpServerSettings settings)
 {
     _context  = context;
     _settings = settings;
     _request  = new RequestImpl(context.Request);
     _response = new ResponseImpl(context.Response);
 }
 public HttpListenerContextImpl(HttpListenerContext context, HttpServerSettings settings)
 {
     _context = context;
     _settings = settings;
     _request = new RequestImpl(context.Request);
     _response = new ResponseImpl(context.Response);
 }
Esempio n. 5
0
        public static void Respond <TRequest>(this Request <TRequest> request)
        {
            if (!typeof(TRequest).IsInterface)
            {
                throw new ArgumentException("Default Implementations can only be created for interfaces");
            }

            Type requestImplType = InterfaceImplementationBuilder.GetProxyFor(typeof(TRequest));

            var responseImpl = new ResponseImpl <TRequest, TRequest>(request, request.Body);

            request.ResponseChannel.Send <Response <TRequest, TRequest> >(responseImpl);
        }
        protected override IAsyncResult BeginSendCore(ServiceRequest request, ExecutionContext context,
                                                      AsyncCallback callback, Object state)
        {
            var req = new HttpRequestMessage(Convert(request.Method), request.BuildRequestUri());

            this.SetRequestContent(req, request);
            this.SetHeaders(req, request);
            HttpClient client = GetClient();
            var        task   = client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);

            ServiceClientImpl.HttpAsyncResult result = new ServiceClientImpl.HttpAsyncResult(callback, state);
            task.ContinueWith((resp) =>
            {
                ServiceResponse serviceResponse = new ResponseImpl(resp.Result);
                result.Complete(serviceResponse);
            });

            return(result);
        }
Esempio n. 7
0
        public static void Respond <TResponse>(this UntypedChannel channel, TResponse response, string requestId)
        {
            var responseImpl = new ResponseImpl <TResponse>(response, requestId);

            channel.Send <Response <TResponse> >(responseImpl);
        }
Esempio n. 8
0
        /// <summary>
        ///   Wraps a message in a response and sends it to the response channel of the request
        /// </summary>
        /// <typeparam name = "TRequest">The type of the request message</typeparam>
        /// <typeparam name = "TResponse">The type of the response message</typeparam>
        /// <param name = "request">The request context</param>
        /// <param name = "response">The response message</param>
        public static void Respond <TRequest, TResponse>(this Request <TRequest> request, TResponse response)
        {
            var responseImpl = new ResponseImpl <TRequest, TResponse>(request, response);

            request.ResponseChannel.Send <Response <TRequest, TResponse> >(responseImpl);
        }