Example #1
0
        public FibonacciDataModel ComputeFibonancciSync(Uri uri, int n)
        {
            log.Info("Execution méthode InvokeService...");
            //Appelle la methode CreateSOAPWebRequest
            HttpWebRequest request = CreateSOAPWebRequest();

            try
            {
                XmlDocument SOAPReqBody = new XmlDocument();
                //SOAP Body requete
                SOAPReqBody.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>  
                <soap:Envelope xmlns:xsi = ""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd = ""http://www.w3.org/2001/XMLSchema"" xmlns:soap = ""http://schemas.xmlsoap.org/soap/envelope/"" >
                    <soap:Body>
                        <Fibonacci xmlns = ""http://lemonway.fr/"">
                           <n>" + n + @"</n>
                        </Fibonacci>
                    </soap:Body>
                </soap:Envelope>");


                using (Stream stream = request.GetRequestStream())
                {
                    SOAPReqBody.Save(stream);
                }
                //Recevoir la réponse de la requete
                using (WebResponse Serviceres = request.GetResponse())
                {
                    using (StreamReader rd = new StreamReader(Serviceres.GetResponseStream()))
                    {
                        //Lire stream
                        var ServiceResult = rd.ReadToEnd();
                        //Ecriture du resultat streaming dans les logs
                        #region AddLogs
                        log.Info("Fin méthode InvokeService");
                        #endregion
                        return(ParseSoapResponse(ServiceResult, n));
                    }
                }
            }
            catch (Exception ex)
            {
                FibonacciDataModel Fibonacci = new FibonacciDataModel
                {
                    FibonacciValue  = n,
                    FibonacciResult = "Web Service Inaccessible pour donner le résultat"
                };

                #region AddLogs
                log.Error("Exception méthode InvokeService : ");
                log.Error("Technical Error : " + ex.Message);
                log.Error("Description : " + Fibonacci.FibonacciResult + " - " + ex.InnerException);
                #endregion

                return(Fibonacci);
            }
        }
Example #2
0
 private void ReportFibonacciInfo(FibonacciDataModel data)
 {
     try
     {
         textCompute_Fibonancci.Invoke(new MethodInvoker(delegate
         {
             textCompute_Fibonancci.Text += $"Pour la valeur { data.FibonacciValue } entré en parametre le résultat est: { data.FibonacciResult.ToString() }.{ Environment.NewLine }";
         }));
     }
     catch
     {
         throw;
     }
 }
Example #3
0
 private FibonacciDataModel ParseSoapResponse(string response, int n)
 {
     log.Info("Execution de la methode ParseSoapResponse... ");
     try
     {
         FibonacciDataModel Fibonacci = new FibonacciDataModel();
         var        soap   = XDocument.Parse(response);
         XNamespace ns     = "http://lemonway.fr/";
         var        result = soap.Descendants(ns + "FibonacciResponse").First().Element(ns + "FibonacciResult").Value;
         Fibonacci.FibonacciValue  = n;
         Fibonacci.FibonacciResult = result.ToString();
         log.Info("Fin de la methode ParseSoapResponse... ");
         return(Fibonacci);
     }
     catch
     {
         throw;
     }
 }
Example #4
0
        public async Task <FibonacciDataModel> ComputeFibonancciAsync(Uri uri, int n)
        {
            log.Info("Execution de la methode ComputeFibonancciAsync... ");
            try
            {
                var soapString = ConstructSoapRequest(n);
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Add("SOAPAction", "http://lemonway.fr/Fibonacci");
                    var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
                    using (var response = await client.PostAsync(uri, content))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var soapResponse = await response.Content.ReadAsStringAsync();

                            log.Info("Fin de la methode ComputeFibonancciAsync... ");
                            return(ParseSoapResponse(soapResponse, n));
                        }
                        else
                        {
                            FibonacciDataModel Fibonacci = new FibonacciDataModel
                            {
                                FibonacciValue  = n,
                                FibonacciResult = "Web Service Inaccessible pour donner le résultat"
                            };

                            #region AddLogs
                            log.Error("Reponse est KO : méthode ComputeFibonancciAsync : ");
                            log.Error("Code Error : " + response.StatusCode);
                            log.Error("Description : " + Fibonacci.FibonacciResult);
                            #endregion

                            return(Fibonacci);
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Example #5
0
        private void RunComputeFibonancciSync()
        {
            log.Info("Execution méthode RunComputeFibonancciSync...");
            #region Get Parameters
            List <int> values = PrepData();
            Uri        myUri  = new Uri(GlobalConfig.Url_WebService, UriKind.Absolute);
            #endregion

            try
            {
                foreach (int val in values)
                {
                    FibonacciDataModel results = ComputeFibonancciSync(myUri, val);
                    ReportFibonacciInfo(results);
                }
                log.Info("Fin d'execution de la méthode RunComputeFibonancciSync...");
            }
            catch
            {
                throw;
            }
        }