public void Error(string s)
 {
     _context.LogTraceError(s);
 }
        private async Task SendInvoke(InvokeContext context, InvokeItem item)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(item.Request.Url);

            request.Method  = item.Request.Method;
            request.Timeout = item.TimeoutInSeconds * 1000;

            foreach (var pair in item.Request.Headers)
            {
                switch (pair.Key.ToLowerInvariant())
                {
                case "content-type":
                    request.ContentType = pair.Value;
                    break;

                case "user-agent":
                    request.UserAgent = pair.Value;
                    break;

                default:
                    request.Headers[pair.Key] = pair.Value;
                    break;
                }
            }

            if (string.CompareOrdinal(request.Method, "GET") != 0)
            {
                var    contentData = new List <byte>();
                byte[] data        = Encoding.UTF8.GetBytes(item.Request.Body);
                contentData.AddRange(data);

                request.ContentLength = contentData.Count;
                Stream stream = await request.GetRequestStreamAsync();

                stream.Write(contentData.ToArray(), 0, contentData.Count);
                stream.Flush();
            }

            // Start invoking
            try
            {
                var response = (HttpWebResponse)await request.GetResponseAsync();

                item.Response.StatusCode = (int)response.StatusCode;

                item.Response.Headers.Clear();
                foreach (string key in response.Headers.AllKeys)
                {
                    item.Response.Headers[key] = response.Headers[key];
                }

                Stream responseContentStream = response.GetResponseStream();
                using (StreamReader reader = new StreamReader(responseContentStream))
                {
                    item.Response.Body = reader.ReadToEnd();
                }
            }
            catch (WebException ex)
            {
                if (ex.Response != null && ex.Response is HttpWebResponse)
                {
                    var httpWebResponse = ex.Response as HttpWebResponse;
                    item.Response.StatusCode = (int)httpWebResponse.StatusCode;
                }
                var stream  = ex.Response.GetResponseStream();
                var message = "Error: status:" + ex.Status + "\r\n" + (stream == null ? string.Empty : new StreamReader(stream).ReadToEnd());
                context.LogTraceError(message + " Exception: " + ex.ToString());
            }
            catch (Exception ex)
            {
                context.LogTraceError("Exception: " + ex.ToString());
            }
        }