示例#1
0
 public bool Invoke()
 {
     try
     {
         this.PreCreateRequest();
         this.Error = this.InternalInvoke();
     }
     catch (WebException ex)
     {
         this.Error = ex;
         if (ex.Response != null && ex.Response.Headers != null)
         {
             this.TraceResponse(ServiceValidatorBase.FormatHeaders(ex.Response.Headers));
         }
     }
     catch (InvalidOperationException error)
     {
         this.Error = error;
     }
     if (this.Error != null)
     {
         this.TraceResponse(this.Error.ToString());
     }
     return(this.Error == null);
 }
示例#2
0
        private Exception InternalInvoke()
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.Uri);

            httpWebRequest.Credentials = this.Credentials;
            this.FillRequestProperties(httpWebRequest);
            this.WriteVerbose(Strings.VerboseServiceValidatorUrl(this.Name, this.Uri));
            if (Datacenter.IsMultiTenancyEnabled())
            {
                this.WriteVerbose(Strings.VerboseServiceValidatorCredential(this.Credentials.UserName, this.Credentials.Password));
            }
            else
            {
                this.WriteVerbose(Strings.VerboseServiceValidatorCredential(this.Credentials.UserName, "******"));
            }
            string message = null;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                if (this.FillRequestStream(memoryStream))
                {
                    byte[] array = memoryStream.ToArray();
                    message = Encoding.UTF8.GetString(array);
                    using (Stream requestStream = httpWebRequest.GetRequestStream())
                    {
                        requestStream.Write(array, 0, array.Length);
                    }
                }
            }
            WebResponse webResponse = null;
            Exception   result;

            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                try
                {
                    webResponse = httpWebRequest.GetResponse();
                }
                finally
                {
                    this.Latency = stopwatch.ElapsedMilliseconds;
                    this.TraceRequest(ServiceValidatorBase.FormatHeaders(httpWebRequest.Headers));
                    this.TraceRequest(message);
                }
                this.TraceResponse(ServiceValidatorBase.FormatHeaders(webResponse.Headers));
                using (Stream responseStream = webResponse.GetResponseStream())
                {
                    using (StreamReader streamReader = new StreamReader(responseStream))
                    {
                        string text = streamReader.ReadToEnd();
                        if (this.TraceResponseBody)
                        {
                            this.TraceResponse(text);
                        }
                        byte[] bytes = Encoding.UTF8.GetBytes(text);
                        using (MemoryStream memoryStream2 = new MemoryStream(bytes))
                        {
                            result = this.ValidateResponse(memoryStream2);
                        }
                    }
                }
            }
            finally
            {
                if (webResponse != null)
                {
                    ((IDisposable)webResponse).Dispose();
                }
            }
            return(result);
        }