Exemplo n.º 1
0
        public static string GetServiceAddress(string module)
        {
            try
            {
                string caissePath = HttpContext.Current.Server.MapPath(@"~/Config/ClientConfig.xml");
                //String caissePath = System.Web.HttpServerUtility.MapPath();
                String contenuXml = String.Empty;

                using (FileStream stream = new FileStream(caissePath, FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        List <ConfigClass> listeconfigs = new List <ConfigClass>();
                        XmlSerializer      serializer   = new XmlSerializer(typeof(ConfigClass));
                        contenuXml = reader.ReadToEnd();

                        XElement rootElement           = XElement.Parse(contenuXml);
                        IEnumerable <XElement> caisses = rootElement.Descendants("ConfigClass");

                        foreach (XElement el in caisses)
                        {
                            using (MemoryStream memStream = new MemoryStream(Encoding.Unicode.GetBytes(el.ToString())))
                            {
                                listeconfigs.Add((ConfigClass)serializer.Deserialize(memStream));
                            }
                        }

                        ConfigClass config = listeconfigs.FirstOrDefault(print => print.module.Equals(module));
                        return(config.address);
                    }
                }
            }
            catch (Exception ex)
            {
                //PrintingsServiceClient printError = new PrintingsServiceClient(Protocole(),EndPoint());
                //printError.SetErrorsFromSilverlightWebPrinting(GetCurrentMethod(), ex.Message);
                throw ex;
            }
        }