Example #1
0
        public List <string> GetClientNamesFromConfigFile()
        {
            List <string>            ClientNames = null;
            string                   name;
            Configuration            appConfig    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
            ClientSection            clients      = serviceModel.Client;

            ChannelEndpointElementCollection cepec = clients.Endpoints;

            if (cepec.Count > 0)
            {
                ClientNames       = new List <string>();
                m_ClientEndPoints = new List <EndPoint>();

                foreach (ChannelEndpointElement cepe in cepec)
                {
                    string[] sa = cepe.Contract.ToString().Split('.');
                    name = sa[0] + "(" + cepe.Binding + ")";


                    m_ClientEndPoints.Add(new EndPoint(cepe.Name, sa[0]));
                    ClientNames.Add(name);
                }
            }

            return(ClientNames);
        }
 // Methods
 internal ConfigWriter(System.Configuration.Configuration configuration)
 {
     this.bindingsSection = BindingsSection.GetSection(configuration);
     ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
     this.channels = sectionGroup.Client.Endpoints;
     this.config = configuration;
 }
        private static ChannelEndpointElement GetDefaultEndpointForServiceType(
            Type serviceInterfaceType,
            string endpointConfigurationName,
            ChannelEndpointElementCollection endpoints)
        {
            var endpointsForServiceType = endpoints.Cast <ChannelEndpointElement>()
                                          .Where(e => e.Contract == serviceInterfaceType.FullName || serviceInterfaceType.FullName.EndsWith(e.Contract))
                                          .ToList();

            if (!string.IsNullOrEmpty(endpointConfigurationName))
            {
                endpointsForServiceType = endpointsForServiceType.Where(e => e.Name == endpointConfigurationName).ToList();
            }

            if (endpointsForServiceType.Count == 0)
            {
                string message = string.Format(
                    "Could not find default endpoint element that references contract '{0}' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.",
                    serviceInterfaceType.FullName);

                throw new InvalidOperationException(message);
            }

            if (endpointsForServiceType.Count > 1)
            {
                string message = string.Format(
                    "An endpoint configuration section for contract '{0}' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.",
                    serviceInterfaceType.FullName);

                throw new InvalidOperationException(message);
            }

            return(endpointsForServiceType[0]);
        }
Example #4
0
        private bool UseConfig()
        {
            try
            {
                string        uri  = Assembly.GetExecutingAssembly().CodeBase;
                string        file = new Uri(uri).LocalPath;
                string        bin  = Path.GetDirectoryName(file);
                DirectoryInfo root = new DirectoryInfo(bin).Parent;

                Configuration            config     = WebConfigurationManager.OpenWebConfiguration("/");
                ServiceModelSectionGroup sectionGrp = ServiceModelSectionGroup.GetSectionGroup(config);

                ChannelEndpointElementCollection endpoints = sectionGrp.Client.Endpoints;
                foreach (ChannelEndpointElement endpoint in endpoints)
                {
                    if (endpoint.Name == AppConfig.EndpointConfig)
                    {
                        Log.Write(TraceEventType.Information, "CompareService: service.model section found");
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(TraceEventType.Error, "{0}", ex);
            }
            Log.Write(TraceEventType.Information, "CompareService: service.model section not found");
            return(false);
        }
Example #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;

            ChannelEndpointElementCollection endpointCollection = clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
            List <string> endpointNames = new List <string>();

            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                if (endpointElement.Address.AbsolutePath.ToLower().Contains("pubsubservice.svc"))
                {
                    txtPubSubURI.Text    = endpointElement.Address.AbsoluteUri;
                    txtPubSubURI.Enabled = false;
                    break;
                }
            }

            txtURL.Text = ConfigurationManager.AppSettings["EPSURL"].ToString();

            txtUser.Text     = ConfigurationManager.AppSettings["UserName"].ToString();
            txtPassword.Text = ConfigurationManager.AppSettings["Password"].ToString();

            this.Text    = "FriendlyDBName = " + System.Configuration.ConfigurationManager.AppSettings["FriendlyName"];
            txtFDBN.Text = System.Configuration.ConfigurationManager.AppSettings["FriendlyName"];

            LoadMessageTypes();
        }
Example #6
0
        private static List <string> GetEndPointList()
        {
            List <string> endpointNames = new List <string>();
            ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;

            if (clientSection != null)
            {
                var propertyInformation = clientSection.ElementInformation.Properties[string.Empty];

                if (propertyInformation != null)
                {
                    ChannelEndpointElementCollection endpointCollection = propertyInformation.Value as ChannelEndpointElementCollection;

                    if (endpointCollection != null)
                    {
                        foreach (var endPoint in endpointCollection)
                        {
                            if (((ChannelEndpointElement)endPoint).Contract == "Intertoll.Toll.DataImport.DataRequest.ITollDataImportDataRequestService")
                            {
                                {
                                    Console.WriteLine(((ChannelEndpointElement)endPoint).Name);
                                    endpointNames.Add(((ChannelEndpointElement)endPoint).Name);
                                }
                            }
                        }
                    }
                }
            }
            return(endpointNames);
        }
Example #7
0
        public static List <Endpoint> LoadEndpointsFromConfig(string configPath)
        {
            List <Endpoint> list = new List <Endpoint>();

            try
            {
                if (configPath == null)
                {
                    var configSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
                    ChannelEndpointElementCollection endpointElCollection = configSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
                    foreach (ChannelEndpointElement element in endpointElCollection)
                    {
                        list.Add(new Endpoint()
                        {
                            EndPointName = element.Name,
                            EndPointPath = element.Address,
                            BindingName  = element.BindingConfiguration
                        });
                    }
                }
                else
                {
                }
            }
            catch
            {
                throw new Exception("Cannot load endpoints! Please check *.config file.");
            }
            return(list);
        }
        internal ConfigWriter(System.Configuration.Configuration configuration)
        {
            this.bindingsSection = BindingsSection.GetSection(configuration);
            ServiceModelSectionGroup sectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);

            this.channels = sectionGroup.Client.Endpoints;
            this.config   = configuration;
        }
Example #9
0
        public static IEnumerable <string> GetEndpointNames()
        {
            ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
            ChannelEndpointElementCollection endpointCollection =
                clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;

            return(endpointCollection.Cast <ChannelEndpointElement>().Select(x => x.Name));
        }
        internal ConfigWriter(Configuration configuration)
        {
            this.bindingTable = new Dictionary<Binding, BindingDictionaryValue>();

            this.bindingsSection = BindingsSection.GetSection(configuration);

            ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
            this.channels = serviceModelSectionGroup.Client.Endpoints;
            this.config = configuration;
        }
Example #11
0
        internal ConfigWriter(Configuration configuration)
        {
            this.bindingTable = new Dictionary <Binding, BindingDictionaryValue>();

            this.bindingsSection = BindingsSection.GetSection(configuration);

            ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);

            this.channels = serviceModelSectionGroup.Client.Endpoints;
            this.config   = configuration;
        }
Example #12
0
        /// <summary>
        /// Gets the web service adress.
        /// </summary>
        /// <returns>
        /// The web service uri if available, otherwise null.
        /// </returns>
        public System.Uri GetWebServiceURI()
        {
            var clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
            ChannelEndpointElementCollection endpointCollection = (ChannelEndpointElementCollection)clientSection.ElementInformation.Properties [string.Empty].Value;

            if (endpointCollection.Count >= 1)
            {
                return(endpointCollection[0].Address);
            }
            else
            {
                return(null);
            }
        }
Example #13
0
        public void Endpoints()
        {
            ServiceModelSectionGroup         g   = GetConfig("Test/config/test1");
            ChannelEndpointElementCollection col = g.Client.Endpoints;

            Assert.AreEqual(1, col.Count, "initial count");
            ChannelEndpointElement e = col [0];

            Assert.AreEqual(String.Empty, e.Name, "0.Name");
            Assert.AreEqual("IFoo", e.Contract, "0.Contract");
            Assert.AreEqual("basicHttpBinding", e.Binding, "0.Binding");
            col.Add(new ChannelEndpointElement());
            Assert.AreEqual(2, col.Count, "after Add()");
        }
        static void Main(string[] args)
        {
            Console.WriteLine(ConfigurationManager.AppSettings["testProp"]);

            DevModeSetting devMode = new DevModeSetting();


            //Get Mode from Arg
            //devMode = DevModeSettingHandler.GetDevModeSetting(args[0]);
            //Get Mode from Code
            devMode = DevModeSettingHandler.GetDevModeSetting("debug");

            //Read From Section
            Console.WriteLine(devMode.TestProp);
            //Console.ReadLine();

            //Read From AppSetting
            Console.WriteLine(ConfigurationManager.AppSettings["testProp"]);
            //Console.ReadLine();

            //Update AppSetting From Section
            ConfigurationManager.AppSettings["testProp"] = devMode.TestProp;
            Console.WriteLine(ConfigurationManager.AppSettings["testProp"]);

            devMode.TestProp = ConfigurationManager.AppSettings["testProp"];
            Console.WriteLine(devMode.TestProp);
            //Console.ReadLine();

            ClientSection clientSection =
                ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;

            ChannelEndpointElementCollection endpointCollection = clientSection?.Endpoints;
            List <string> endpointNames = new List <string>();

            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                endpointNames.Add(endpointElement.Name);
                Console.WriteLine($"{endpointElement.Name} : {endpointElement.Address}");
                Console.WriteLine($"{endpointElement.Binding}");
            }

            Console.ReadLine();
        }
Example #15
0
        public void GetServicesTest()
        {
            ClientSection client = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
            ChannelEndpointElementCollection endpoints = client.Endpoints;
            ChannelEndpointElement           endpoint  = null;

            foreach (ChannelEndpointElement item in endpoints)
            {
                if (WCFServicesHelper.EndpointConfig.Equals(item.Name))
                {
                    endpoint = item;
                    break;
                }
            }

            using (ChannelFactory <IService1> endpointServices = WCFServicesHelper.Current.ChannelFactoryIService1)
            {
                Assert.AreEqual(endpointServices.Endpoint.Address.Uri, endpoint.Address);
            }
        }
Example #16
0
        public static string GetServerName()
        {
            string serverName = "Unknown";

            ClientSection clientSection =
                ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;

            ChannelEndpointElementCollection endpointCollection =
                clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
            List <string> endpointNames = new List <string>();

            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                if (endpointElement.Contract == "EmployeeService.IEmployeeService")
                {
                    serverName = endpointElement.Address.AbsoluteUri;
                }
            }

            return(serverName);
        }
 /// <remarks/>
 public WebServiceEDIMSGValidateAndReturnDS()
 {
     //this.Url = "http://52.187.30.105/edi/PresentationLayer/WebServiceEDIMSGValidateAndReturnDS.as" +
     //    "mx";
     try
     {
         ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
         ChannelEndpointElementCollection endpointCollection =
             clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
         string URl = "";
         foreach (ChannelEndpointElement endpointElement in endpointCollection)
         {
             if (endpointElement.Name == "WebServiceEDIMSGValidateAndReturnDSSoap")
             {
                 URl = endpointElement.Address.AbsoluteUri;
             }
         }
         this.Url = "" + URl + "";
     }
     catch (Exception ex)//(Exception ex)
     {
         throw ex;
     }
 }
Example #18
0
        /// <summary>
        /// Initialize the example application. If a compatible version of CFX Manager is executing, establish a connection
        /// with it, otherwise start CFX Manager in server (no UI) mode and establish a connection with that instance.
        /// Subscribe to the ClientError event published by the client wrapper. Initialize local member data. Present an
        /// explanatory dialog and exit the application if no compatible version of CFX Manager is installed on the host machine,
        /// or if the client fails for any reason to establish a connection with the CFX Manager API service.
        /// </summary>
        private void InitializeMainForm()
        {
            #region local delegates implementing utilities specific to this method

            // Prepare to establish communications with the CFX Manager API using methods provided by the
            // CFXManagerUtilities class. If a compatible version of CFX Manager is installed and is already
            //executing, do nothing. If it is installed, but not executing, attempt to start it in server (no UI) mode.
            //Returns true IFF a compatible version  of CFX Manager is executing at the completion of the method.
            Func <bool> ReadyCFXManager = () =>
            {
                //If the service endpoint address is not localhost, skip this logic and return true, making the assumption
                //that CFX Manager is running on the remote host, since we cannot detect or start it remotely.
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
                ChannelEndpointElementCollection endpointCollection = clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
                if (endpointCollection[0].Address.Host != "localhost")
                {
                    LogNewLine("The service endpoint address is not localhost. Skipping CFX Manager detection logic.");
                    return(true);
                }

                if (CFXManagerUtilities.APICompatibleCFXManagerIsInstalled)
                {
                    if (!CFXManagerUtilities.CFXManagerIsExecuting)
                    {
                        LogNewLine("Starting CFX Manager in server mode..");
                        //Note that this call will block this thread for up to several seconds while CFX Manager initializes.
                        return(CFXManagerUtilities.StartCFXManagerAsServer());
                    }
                    else
                    {
                        LogNewLine("Detected executing instance of CFX Manager..");
                    }
                    return(true);
                }
                return(false);
            };

            //Initialize the system timer that is used to systematically poll the CFX Manager API for status updates
            Action <Form> StartTimer = (Form child) =>
            {
                this.m_status_update_timer.Interval       = c_status_update_interval;
                m_status_update_timer.Elapsed            += new ElapsedEventHandler(UpdateTimer_Elapsed);
                m_status_update_timer.SynchronizingObject = child;
                m_status_update_timer.AutoReset           = true;
                m_status_update_timer.Start();
            };

            #endregion

            // InitializeMainForm() Entry Point
            this.Text = string.Format(c_app_name);
            LogNewLine(string.Format("{0} is initializing..", c_app_name));
            m_ClientWrapper.ClientError += HandleClientError;
            if (ReadyCFXManager())
            {
                if (m_ClientWrapper.OpenClient())
                {
                    LogNewLine("Client connection established with CFX Manager API service..");
                    m_am_connected = true;
                    StartTimer(this);
                }
                else
                {
                    LogNewLine(string.Format("The {0} was unable to connect to the CFX Manager API service. ", c_app_name));
                    LogNewLine(string.Format("Review the log above for possible causes, then click the close box to exit the application. "));
                    m_panel_buttons.Enabled = false;
                }
            }
            else
            {
                string fail_msg = string.Format("CFX Manager Version {0} or higher must be installed in order to run the {1}. The application will now exit.",
                                                CFXManagerUtilities.MiniumumCFXManagerVersion, c_app_name);
                MessageBox.Show(string.Format("{0}", fail_msg), c_app_name, MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                Close();
            }
        }
        // GET: api/ReportGenerate
        public IEnumerable <Report> Get()
        {
            string        reportServiceUser     = CloudConfigurationManager.GetSetting("reportServiceUser");
            string        reportServicePassword = CloudConfigurationManager.GetSetting("reportServicePassword");
            ClientSection clientSec             = System.Configuration.ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
            ChannelEndpointElementCollection endpointCollection = clientSec.Endpoints;

            endpointNames = new List <string>();
            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                if (String.Compare(endpointElement.Contract, "ReportingService.ReportingService2010Soap", true) == 0)
                {
                    endpointNames.Add(endpointElement.Name);
                }
            }
            int retry = endpointNames.Count;

            blacklist = new Dictionary <string, DateTime>();

            while (retry > 0)
            {
                string rsEndpoint = PickReportingService();
                try
                {
                    System.Net.NetworkCredential      clientCredential = new System.Net.NetworkCredential(reportServiceUser, reportServicePassword);
                    rs.ReportingService2010SoapClient rsClient         = new rs.ReportingService2010SoapClient(rsEndpoint);
                    rsClient.ClientCredentials.Windows.ClientCredential          = clientCredential;
                    rsClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                    rs.TrustedUserHeader userHeader = new rs.TrustedUserHeader();
                    rs.CatalogItem[]     items;

                    Trace.TraceInformation("Connecting to reporting service " + rsEndpoint);
                    rsClient.Open();
                    Trace.TraceInformation("Connected to reporting service " + rsEndpoint);
                    rs.ServerInfoHeader infoHeader = rsClient.ListChildren(userHeader, reportPath, true, out items);
                    Trace.TraceInformation("Fetched reports from reporting service " + rsEndpoint);

                    reports = new List <Report>(items.Length);

                    foreach (var item in items)
                    {
                        if (String.Compare(item.TypeName, "Report", true) == 0)
                        {
                            Report it = new Report {
                                Name = item.Name, Path = item.Path, ModifiedDate = item.ModifiedDate
                            };
                            reports.Add(it);
                        }
                    }
                    rsClient.Close();
                    break;
                }
                catch (Exception e)
                {
                    Trace.TraceError("Failed to fetch reports from reporting service. " + e.Message);
                    blacklist[rsEndpoint] = DateTime.Now;
                    --retry;
                    if (retry == 0)
                    {
                        throw;
                    }
                }
            }

            return(reports);
        }