/// <summary> /// Close the WCF connector. /// </summary> public void Close() { Stop(); svcHost = null; }
/// <summary> /// Prepares the parameters for this connector and ensures that resources exist so the <seealso cref="Start"/> operation /// succeeds. /// </summary> public void Open() { // Connection string if (ConnectionString == null) throw new ConnectorException(ConnectorException.MSG_NULL_CONNECTION_STRING, ConnectorException.ReasonType.NullConnectionString); else if (Formatter == null) throw new ConnectorException(ConnectorException.MSG_NULL_FORMATTER, ConnectorException.ReasonType.NullFormatter); Dictionary<string, List<string>> conf = ConnectionStringParser.ParseConnectionString(ConnectionString); string epAddress = string.Empty, epBinding = string.Empty, epContract = string.Empty, epBindingConfig = string.Empty; // Load List<string> tmpValues; if (conf.TryGetValue("servicename", out tmpValues)) serviceName = tmpValues[0]; if (conf.TryGetValue("endpointaddress", out tmpValues)) epAddress = tmpValues[0]; if (conf.TryGetValue("bindingtype", out tmpValues)) epBinding = tmpValues[0]; if (conf.TryGetValue("bindingconfig", out tmpValues)) epBindingConfig = tmpValues[0]; epContract = typeof(IConnectorContract).FullName; // Service host svcHost = null; if (String.IsNullOrEmpty(epAddress)) { svcHost = new WcfServiceHost(serviceName, typeof(ConnectorService)); } else { svcHost = new WcfServiceHost(null, typeof(ConnectorService)); if (!String.IsNullOrEmpty(epBindingConfig)) svcHost.AddServiceEndpoint( epContract, epBinding == "basicHttpBinding" ? (Binding)(new BasicHttpBinding(epBindingConfig)) : epBinding == "wsHttpBinding" ? (Binding)(new WSHttpBinding(epBindingConfig)) : null, epAddress ); else svcHost.AddServiceEndpoint( epContract, epBinding == "basicHttpBinding" ? (Binding)(new BasicHttpBinding()) : epBinding == "wsHttpBinding" ? (Binding)(new WSHttpBinding()) : null, epAddress ); } svcHost.ConnectorHost = this; }