Esempio n. 1
0
        /// <summary>
        /// This method makes a callback to an AsyncResponseParser and takes a service management request and certificate and sends a request to
        /// the management endpoint
        /// </summary>
        public Task <WebResponse> MakeASyncRequest(ServiceManagementRequest serviceManagementRequest, ServiceManager.AsyncResponseParser parser, ServiceManager.AsyncResponseException error)
        {
            if (ServicePointManager.ServerCertificateValidationCallback == null)
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
            }
            ServicePointManager.DefaultConnectionLimit = 40;

            HttpWebRequest request = BuildAzureHttpRequest(serviceManagementRequest);

            return(Task <WebResponse> .Factory
                   .FromAsync(request.BeginGetResponse, request.EndGetResponse, null)
                   .ContinueWith <WebResponse>(task =>
            {
                if (task.Exception != null)
                {
                    if (task.Exception.InnerException.GetType() == typeof(WebException))
                    {
                        error((WebException)task.Exception.InnerException);
                    }
                    return null;
                }
                var response = (HttpWebResponse)task.Result;
                parser(response);
                return response;
            }));
        }
Esempio n. 2
0
 public void MakeASyncRequest(ServiceManagementRequest serviceManagementRequest, ServiceManager.AsyncResponseParser parser)
 {
     MakeASyncRequest(serviceManagementRequest, parser, null);
 }