public void ClientSectionTest() { ClientSection client = LoadManager().GetClient(); Assert.IsNotNull(client); Assert.AreEqual(1, client.Endpoints.Count); }
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(); }
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); }
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); }
public static bool IsEndpointDefinedInConfiguration(string endpointName, Type contractType) { if (string.IsNullOrEmpty(endpointName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointName"); } if (contractType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractType"); } bool wildcard = string.Equals(endpointName, "*", StringComparison.Ordinal); ClientSection section = ClientSection.GetSection(); foreach (ChannelEndpointElement element in section.Endpoints) { if ((!wildcard && (element.Name != endpointName)) || (element.Contract != contractType.FullName)) { continue; } return(true); } return(false); }
private ServiceEndpoint GetServiceEndpointByConfig(string configName, string endpointConfigurationName) { ServiceEndpoint serviceEndpoint = null; DsConfigurationManager dcm = new DsConfigurationManager(); System.Configuration.Configuration config = dcm.Get <System.Configuration.Configuration>(ConfigurationFileHelper.GetAddinConfigurationFilePath(configName)); ClientSection cconfig = config.GetSection(GlobalParams.ClientHostSession) as ClientSection; if (cconfig != null) { if (cconfig.Endpoints.Count > 0) { foreach (ChannelEndpointElement e in cconfig.Endpoints) { if (e.Name != endpointConfigurationName) { continue; } channelType = TypeResolutionUtils.ResolveType(e.Contract); serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(channelType), WCFMateHelper.BindingFactory(config, e), new EndpointAddress(e.Address)); } } } if (serviceEndpoint == null) { throw new ArgumentNullException("The configuration file{0},The client access to WCF configuration information is not correct".FormatString(configName)); } return(serviceEndpoint); }
/// <summary> /// 更改配置文件 /// </summary> /// <param name="serverIp"></param> public void ChangeWCF_URL(string serverIp) { Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); ConfigurationSectionGroup sct = config.SectionGroups["system.serviceModel"]; ServiceModelSectionGroup serviceModelSectionGroup = sct as ServiceModelSectionGroup; ClientSection clientSection = serviceModelSectionGroup.Client; foreach (ChannelEndpointElement item in clientSection.Endpoints) { //string[] str = item.Address.ToString().Split('/'); //string pattern = ""; //for (int i = 0; i < str.Length - 2; i++) // pattern += str[i] + '/'; string address = item.Address.ToString(); //string replacement = string.Format("{0}", serverIp); //address = Regex.Replace(address, pattern, replacement); address = "http://" + serverIp + ":8732/Design_Time_Addresses/WcfService/Service1/"; try { item.Address = new Uri(address); } catch (Exception ex) { LogFileManager.ObjLog.debug(ex.Message, ex); return; } } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("system.serviceModel"); }
/// <summary> /// Recreates the publishing proxy after loading the settings againg from the config file /// </summary> /// <param name="publishServiceProxy">The publish service proxy.</param> /// <returns>A newly created publishing proxy client</returns> internal static PublishingServiceClient RecreatePublishingProxy(PublishingServiceClient publishServiceProxy) { try { // Close the communication channel if (publishServiceProxy.State != CommunicationState.Closed) { publishServiceProxy.Close(); } // Wait for retry interval before retrying. Thread.Sleep(RetryInterval); // Reload the configuration for the service ConfigurationManager.RefreshSection("system.serviceModel/client"); ClientSection clientSection = ((ClientSection)ConfigurationManager.GetSection("system.serviceModel/client")); return(new PublishingServiceClient("WSHttpBinding_IPublishingService", clientSection.Endpoints[0].Address.AbsoluteUri)); } catch (Exception ex) { Globals.TraceMessage(TraceEventType.Error, ex.ToString(), TraceMessages.ExceptionCreatingPublishingServiceProxy); } return(new PublishingServiceClient("WSHttpBinding_IPublishingService")); }
/// <summary> /// Checks the specified configuration manager. /// </summary> /// <param name="configurationManager">The configuration manager.</param> /// <returns></returns> public override ProblemCollection Check(ServiceModelConfigurationManager configurationManager) { // Check for service endpoints foreach (ServiceElement serviceElement in configurationManager.GetServices()) { foreach (ServiceEndpointElement endpointElement in serviceElement.Endpoints) { if (endpointElement.Binding.Equals(CustomBindingAttributeValue, StringComparison.InvariantCultureIgnoreCase)) { CheckRuleForCustomBinding(configurationManager.GetCustomBinding(endpointElement.BindingConfiguration)); } } } // Check for client endponts ClientSection client = configurationManager.ServiceModelSection.Client; if (client != null) { foreach (ChannelEndpointElement clientEndpoint in client.Endpoints) { if (clientEndpoint.Binding.Equals(CustomBindingAttributeValue, StringComparison.InvariantCultureIgnoreCase)) { CheckRuleForCustomBinding(configurationManager.GetCustomBinding(clientEndpoint.BindingConfiguration)); } } } return(base.Problems); }
/// <summary> /// LookupEndpoint /// </summary> /// <param name="endpointName"></param> /// <returns></returns> private string LookupEndpoint(string endpointName) { if (string.IsNullOrWhiteSpace(endpointName)) { return("*"); } Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ClientSection clientSection = ServiceModelSectionGroup.GetSectionGroup(config).Client; ChannelEndpointElement endpointElement = null; foreach (ChannelEndpointElement element in clientSection.Endpoints) { if (element.Name.EndsWith("_" + endpointName, StringComparison.OrdinalIgnoreCase) && element.Contract == typeof(TChannel).FullName) { endpointElement = element; break; } } if (endpointElement == null) { return("*"); } return(endpointElement.Name); }
private void UpdateServiceAddress(string address, string endpointName) { Configuration config = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); ClientSection clientSection = (ClientSection)config.GetSection("system.serviceModel/client"); ChannelEndpointElement endpointElement = null; foreach (ChannelEndpointElement element in clientSection.Endpoints) { if (element.Name == endpointName) { endpointElement = element; break; } } if (endpointElement != null) { endpointElement.Address = new Uri(string.Format("{0}://{1}:{2}{3}", endpointElement.Address.Scheme, address, endpointElement.Address.Port.ToString(), endpointElement.Address.AbsolutePath)); config.Save(); ConfigurationManager.RefreshSection("system.serviceModel/client"); } else { throw new ApplicationException(string.Format("Could not find {0} endpoint configuration section", endpointName)); } }
private Uri getAddressEndpoint_SceWeb() { Uri uriWceWeb = null; try { ClientSection clientSection = (WebConfigurationManager.GetSection(Constantes.SectionEndpointClient) as ClientSection); if (clientSection != null) { foreach (ChannelEndpointElement cee in clientSection.Endpoints) { if (cee.Name == Constantes.NameChannelEndpoint) { uriWceWeb = cee.Address; break; } } return(uriWceWeb); } } catch (Exception ex) { throw; } return(uriWceWeb); }
/// <summary> /// Was this endpoint configured using ServiceModel /// </summary> /// <typeparam name="I"></typeparam> /// <returns></returns> protected virtual bool IsEndpointServiceModelConfigured <I>(out string itemName) { bool result = false; itemName = string.Empty; try { ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection; if (clientSection != null) { foreach (ChannelEndpointElement endpoint in clientSection.Endpoints) { if (endpoint.Contract == typeof(I).FullName) { itemName = endpoint.Name; result = true; break; } } } } catch (Exception ex) { Log(ex.ToString()); } return(result); }
/// <summary> /// 修改system.serviceModel下所有服务终结点的IP地址 /// </summary> /// <param name="configPath">Assembly.GetEntryAssembly().Location</param> /// <param name="serverIP"></param> /// <param name="serverPort"></param> public static void UpdateServiceModelConfig(string configPath, string serverIP, string serverPort) { Configuration config = ConfigurationManager.OpenExeConfiguration(configPath); ConfigurationSectionGroup sec = config.SectionGroups["system.serviceModel"]; ServiceModelSectionGroup serviceModelSectionGroup = sec as ServiceModelSectionGroup; ClientSection clientSection = serviceModelSectionGroup.Client; foreach (ChannelEndpointElement item in clientSection.Endpoints) { string address = ""; //端口号为空 if (string.IsNullOrEmpty(serverPort)) { address = item.Address.Scheme + "://" + serverIP + item.Address.AbsolutePath; } else { address = item.Address.Scheme + "://" + serverIP + ":" + serverPort + item.Address.AbsolutePath; } item.Address = new Uri(address); //string pattern = @"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+\b"; //string address = item.Address.ToString(); //string replacement = string.Format("{0}:{1}", serverIP, serverPort); //address = Regex.Replace(address, pattern, replacement); //item.Address = new Uri(address); } foreach (ServiceElement el in serviceModelSectionGroup.Services.Services) { string address = el.Host.BaseAddresses[0].BaseAddress; int idx = address.IndexOf("/"); string scheme = address.Substring(0, idx + 2); address = address.Replace("net.tcp://", "") .Replace("net.pipe://", "") .Replace("net.msmq://", "") .Replace("http://", "") .Replace("https://", "") .Replace("net.p2p://", ""); idx = address.IndexOf("/"); string absolutePath = address.Substring(idx); //端口号为空 if (string.IsNullOrEmpty(serverPort)) { address = scheme + serverIP + absolutePath; } else { address = scheme + serverIP + ":" + serverPort + absolutePath; } el.Host.BaseAddresses[0].BaseAddress = address; //string pattern = @"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+\b"; //string baseAddress = el.Host.BaseAddresses[0].BaseAddress; //string replacement = string.Format("{0}:{1}", serverIP, serverPort); //string address = Regex.Replace(baseAddress, pattern, replacement); //el.Host.BaseAddresses[0].BaseAddress = address; } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("system.serviceModel"); }
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)); }
public static string GetServiceUrl() { ClientSection clientSection = (ClientSection)WebConfigurationManager.GetSection("system.serviceModel/client"); ChannelEndpointElement endpoint = clientSection.Endpoints[0]; string address = endpoint.Address.ToString(); return(address.Substring(0, address.LastIndexOf("/"))); }
/// <summary> /// Récupère le premier endpoint de la liste des WS du Appconfig /// </summary> /// <returns>Url du WS</returns> public string GetEndPoint() { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration); ClientSection clientSection = serviceModelSectionGroup.Client; return(clientSection.Endpoints[0].Address.AbsoluteUri); }
public Broker() { ClientSection section = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client"); foreach (ChannelEndpointElement elem in section.Endpoints) { storages.Add((IKV)Activator.GetObject(typeof(IKV), elem.Address.ToString())); } }
public static string GetEndpointAddress() { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration); ClientSection clientSection = serviceModelSectionGroup.Client; var el = clientSection.Endpoints[0]; return(el.Address.Host.ToString()); }
public void ClientBindingTest() { ServiceModelConfigurationManager manager = LoadManager(); ClientSection client = manager.GetClient(); CustomBindingElement binding = manager.GetCustomBinding(client.Endpoints[0].BindingConfiguration); SecurityElement securitySection = binding[typeof(SecurityElement)] as SecurityElement; Assert.IsNotNull(securitySection); Assert.AreEqual(AuthenticationMode.UserNameForSslNegotiated, securitySection.SecureConversationBootstrap.AuthenticationMode); }
public void AnuncioCrearCommandExecute() { if (itemAnuncio.Imagen == "" || itemAnuncio.Descripcion == "" || itemAnuncio.URL == "" || itemAnuncio.FechaCaducidad == null || itemAnuncio.Tipo == 0) { MessageBox.Show("No ha introducido todos los datos", "Error"); } else { ServiceClient service = new ServiceClient(); MessageBoxResult result = MessageBox.Show("¿Está seguro de que desea crear este anuncio?", "Confirmación", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { // Creamos la imagen y obtenemos su ID int id = service.NuevoInmueblate_Anuncio_CrearAnuncio(itemAnuncio.Imagen, itemAnuncio.Descripcion, itemAnuncio.FechaCaducidad, itemAnuncio.Tipo, itemAnuncio.URL); // Con ese ID, subimos la imagen con el nombre del ID y actualizamos la imagen con la nueva dirección y la ID #region subirImagen // Creo una la imagen con la ruta enviada Image imagen = Image.FromFile(itemAnuncio.Imagen); // Hago el stream para enviarla al servicio WCF MemoryStream ms = new MemoryStream(); imagen.Save(ms, imagen.RawFormat); byte[] imageBytes = ms.ToArray(); string base64String = Convert.ToBase64String(imageBytes); // Envio al servicio la imagen en un stream de datos y el nombre que se le va a asignar (idealmente sería el ID del anuncio) string direccion = service.subirAnuncio(base64String, id, itemAnuncio.Imagen.Substring(itemAnuncio.Imagen.LastIndexOf('.'))); // Leo la dirección IP del servicio, que será donde se va a almacenar la imagen Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration); ClientSection clientSection = serviceModelSectionGroup.Client; var el = clientSection.Endpoints[0]; string ip = el.Address.ToString(); ip = ip.Substring(0, ip.LastIndexOf('/')); itemAnuncio.Imagen = ip + direccion; #endregion service.NuevoInmueblate_Anuncio_ModificarAnuncio(id, itemAnuncio.Imagen, itemAnuncio.Descripcion, itemAnuncio.FechaCaducidad, itemAnuncio.Tipo, itemAnuncio.URL); NavigationViewModel.Instance.cleanBack(); NavigationViewModel.Instance.CurrentPage = new views.Anuncio.Anuncios(); NavigationViewModel.Instance.CurrentPage.DataContext = new AnunciosViewModel(); } } }
/// <summary> /// 获取客户端节 /// </summary> /// <param name="configName">配置名</param> /// <returns></returns> private static ClientSection GetClientSection(string configName) { ClientSection clientSection = null; SetConfigFile(configName); if (config != null) { clientSection = config.GetSection("system.serviceModel/client") as ClientSection; } return(clientSection); }
public void ClientBehaviorTest() { ServiceModelConfigurationManager manager = LoadManager(); ClientSection client = manager.GetClient(); NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> behavior = manager.GetBehavior(client.Endpoints[0].BehaviorConfiguration); ClientCredentialsElement credentialsSection = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ClientCredentialsElement>(behavior); Assert.AreEqual(Constants.TestCert, credentialsSection.ClientCertificate.FindValue); Assert.AreEqual(System.ServiceModel.Security.X509CertificateValidationMode.ChainTrust, credentialsSection.ServiceCertificate.Authentication.CertificateValidationMode); }
private static BrokerClient GetRandomBroker() { ClientSection section = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client"); foreach (ChannelEndpointElement elem in section.Endpoints) { brokers.Add(new BrokerClient(elem.Name)); } return(brokers.ElementAt(random.Next(brokers.Count()))); }
public void Load() { var clientSection = ConfigurationManager.GetSection(@"system.serviceModel\client") as ClientSection; if (clientSection == null) { return; } this.client = clientSection; this.knownServices = WcfClientEndpointExplorer.GetKnownServices(clientSection).ToArray(); }
static ConfigManager() { ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap() { ExeConfigFilename = CONFIG_PATH }; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None); _clientSection = config.GetSection("system.serviceModel/client") as ClientSection; _appSettingSection = config.AppSettings; _connectionStringSection = config.ConnectionStrings; }
/// <summary> /// 读取EndpointAddress /// </summary> /// <param name="endpointName"></param> /// <returns></returns> private string GetEndpointAddress(string endpointName) { ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection; foreach (ChannelEndpointElement item in clientSection.Endpoints) { if (item.Name == endpointName) { return(item.Address.ToString()); } } return(string.Empty); }
public static ChannelEndpointElement GetServiceModelEndpoint(String name) { ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection; List<ChannelEndpointElement> channelEndpointElements = new List<ChannelEndpointElement>(); foreach (ChannelEndpointElement endpointElement in clientSection.Endpoints) { channelEndpointElements.Add(endpointElement); } ChannelEndpointElement channelEndpointElement = channelEndpointElements.Single(x => x.Name == name); return channelEndpointElement; }
public WsdlImporter CreateDataContractSerializerImporter(MetadataSet metaData) { Collection <IWsdlImportExtension> wsdlImportExtensions = ClientSection.GetSection().Metadata.LoadWsdlImportExtensions(); for (int i = 0; i < wsdlImportExtensions.Count; i++) { if (wsdlImportExtensions[i].GetType() == typeof(XmlSerializerMessageContractImporter)) { wsdlImportExtensions.RemoveAt(i); } } return(new WsdlImporter(metaData, null, wsdlImportExtensions)); }
private Collection <IWsdlImportExtension> LoadWsdlImportExtensions() { if (this.configuration != null) { ServiceModelConfigurationManager manager = new ServiceModelConfigurationManager(this.configuration); ClientSection client = manager.GetClient(); if (client != null) { return(client.Metadata.LoadWsdlImportExtensions()); } } return(null); }