public void NullUrlResolvesToNullClientProtocolSetup() { var protocol = ClientProtocolSetup.GetClientProtocol("null://NullChannel:1234/svc"); Assert.AreEqual(typeof(NullClientProtocolSetup), protocol.GetType()); }
public void TcpexUrlResolvesToTcpDuplexProtocolSetup() { var protocol = ClientProtocolSetup.GetClientProtocol("tcpex://localhost:1234/svc"); Assert.AreEqual(typeof(TcpDuplexClientProtocolSetup), protocol.GetType()); }
public void HttpUrlResolvesToHttpCustomProtocolSetup() { var protocol = ClientProtocolSetup.GetClientProtocol("http://some/url"); Assert.AreEqual(typeof(HttpCustomClientProtocolSetup), protocol.GetType()); }
public void IpcUrlResolvesToIpcBinaryProtocolSetup() { var protocol = ClientProtocolSetup.GetClientProtocol("ipc://some/url"); Assert.AreEqual(typeof(IpcBinaryClientProtocolSetup), protocol.GetType()); }
/// <summary> /// Creates a new instance of the ZyanConnection class. /// </summary> /// <param name="serverUrl">URL of remote server (e.G. "tcp://server1:46123/myapp").</param> /// <param name="protocolSetup">Protocol and communication settings.</param> /// <param name="credentials">Login credentials.</param> /// <param name="autoLoginOnExpiredSession">Specifies whether the proxy should relogin automatically when the session expired.</param> /// <param name="keepSessionAlive">Specifies whether the session should be automaticly kept alive.</param> public ZyanConnection(string serverUrl, IClientProtocolSetup protocolSetup, AuthCredentials credentials, bool autoLoginOnExpiredSession, bool keepSessionAlive) { if (string.IsNullOrEmpty(serverUrl)) { throw new ArgumentException(LanguageResource.ArgumentException_ServerUrlMissing, "serverUrl"); } if (protocolSetup == null) { // try to select the protocol automatically protocolSetup = ClientProtocolSetup.GetClientProtocol(serverUrl); if (protocolSetup == null) { throw new ArgumentNullException("protocolSetup"); } } if (!protocolSetup.IsUrlValid(serverUrl)) { throw new ArgumentException(LanguageResource.ArgumentException_ServerUrlIsInvalid, "serverUrl"); } _proxies = new List <WeakReference>(); _protocolSetup = protocolSetup; _sessionID = Guid.NewGuid(); _serverUrl = serverUrl; _autoLoginOnExpiredSession = autoLoginOnExpiredSession; _keepSessionAlive = keepSessionAlive; if (_autoLoginOnExpiredSession) { _autoLoginCredentials = credentials; } _serializationHandling = new SerializationHandlerRepository(); CallInterceptionEnabled = false; _callInterceptors = new CallInterceptorCollection(); RegisterStandardSerializationHandlers(); string[] addressParts = _serverUrl.Split('/'); _componentHostName = addressParts[addressParts.Length - 1]; _remotingChannel = _protocolSetup.CreateChannel(); if (!ZyanSettings.DisableUrlRandomization) { _remotingChannel = ChannelWrapper.WrapChannel(_remotingChannel, _protocolSetup.ChannelName); } if (_remotingChannel != null) { var registeredChannel = ChannelServices.GetChannel(_remotingChannel.ChannelName); if (registeredChannel == null) { ChannelServices.RegisterChannel(_remotingChannel, false); } else { _remotingChannel = registeredChannel; } } else { throw new ApplicationException(LanguageResource.ApplicationException_NoChannelCreated); } var connectionNotification = _remotingChannel as IConnectionNotification; if (connectionNotification != null) { connectionNotification.ConnectionEstablished += Channel_ConnectionEstablished; } string channelName = _remotingChannel.ChannelName; if (credentials == null) { credentials = new AuthCredentials(); } try { credentials.Authenticate(_sessionID, RemoteDispatcher); _registeredComponents = new List <ComponentInfo>(RemoteDispatcher.GetRegisteredComponents()); _sessionAgeLimit = RemoteDispatcher.SessionAgeLimit; } catch (Exception ex) { // unregister remoting channel var registeredChannel = ChannelServices.GetChannel(channelName); if (registeredChannel != null) { ChannelServices.UnregisterChannel(registeredChannel); } // dispose channel if it's disposable var disposableChannel = registeredChannel as IDisposable; if (disposableChannel != null) { disposableChannel.Dispose(); } _remotingChannel = null; _remoteDispatcher = null; throw ex.PreserveStackTrace(); } var reconnectEvents = new Action(ReconnectRemoteEventsCore); var debounceInterval = ZyanSettings.ReconnectRemoteEventsDebounceInterval.TotalMilliseconds; ReconnectRemoteEvents = reconnectEvents.Debounce((int)debounceInterval); StartKeepSessionAliveTimer(); lock (_connections) { _connections.Add(this); } }
/// <summary> /// Creates a new instance of the ZyanConnection class. /// </summary> /// <param name="serverUrl">URL of remote server (e.G. "tcp://server1:46123/myapp").</param> /// <param name="credentials">Login credentials.</param> /// <param name="autoLoginOnExpiredSession">Specifies whether the proxy should relogin automatically when the session expired.</param> /// <param name="keepSessionAlive">Specifies whether the session should be automaticly kept alive.</param> public ZyanConnection(string serverUrl, Hashtable credentials, bool autoLoginOnExpiredSession, bool keepSessionAlive) : this(serverUrl, ClientProtocolSetup.GetClientProtocol(serverUrl), credentials, autoLoginOnExpiredSession, true) { }
/// <summary> /// Creates a new instance of the ZyanConnection class. /// </summary> /// <param name="serverUrl">URL of remote server (e.G. "tcp://server1:46123/myapp")</param> /// <param name="autoLoginOnExpiredSession">Specifies whether the proxy should relogin automatically when the session expired</param> public ZyanConnection(string serverUrl, bool autoLoginOnExpiredSession) : this(serverUrl, ClientProtocolSetup.GetClientProtocol(serverUrl), null, autoLoginOnExpiredSession, !autoLoginOnExpiredSession) { }
/// <summary> /// Creates a new instance of the ZyanConnection class. /// </summary> /// <param name="serverUrl">URL of remote server (e.G. "tcp://server1:46123/myapp")</param> public ZyanConnection(string serverUrl) : this(serverUrl, ClientProtocolSetup.GetClientProtocol(serverUrl), null, false, true) { }
/// <summary> /// Creates a new instance of the ZyanConnection class. /// </summary> /// <param name="serverUrl">URL of remote server (e.G. "tcp://server1:46123/myapp").</param> /// <param name="protocolSetup">Protocol and communication settings.</param> /// <param name="credentials">Login credentials.</param> /// <param name="autoLoginOnExpiredSession">Specifies whether the proxy should relogin automatically when the session expired.</param> /// <param name="keepSessionAlive">Specifies whether the session should be automaticly kept alive.</param> public ZyanConnection(string serverUrl, IClientProtocolSetup protocolSetup, Hashtable credentials, bool autoLoginOnExpiredSession, bool keepSessionAlive) { if (string.IsNullOrEmpty(serverUrl)) { throw new ArgumentException(LanguageResource.ArgumentException_ServerUrlMissing, "serverUrl"); } if (protocolSetup == null) { // try to select the protocol automatically protocolSetup = ClientProtocolSetup.GetClientProtocol(serverUrl); if (protocolSetup == null) { throw new ArgumentNullException("protocolSetup"); } } _proxies = new List <WeakReference>(); _protocolSetup = protocolSetup; _sessionID = Guid.NewGuid(); _serverUrl = serverUrl; _autoLoginOnExpiredSession = autoLoginOnExpiredSession; _keepSessionAlive = keepSessionAlive; if (_autoLoginOnExpiredSession) { _autoLoginCredentials = credentials; } _serializationHandling = new SerializationHandlerRepository(); CallInterceptionEnabled = false; _callInterceptors = new CallInterceptorCollection(); RegisterStandardSerializationHandlers(); string[] addressParts = _serverUrl.Split('/'); _componentHostName = addressParts[addressParts.Length - 1]; _transportAdapter = _protocolSetup.CreateTransportAdapter(); //TODO: Implement URL randomization without .NET Remoting dependency //if (AllowUrlRandomization) //{ // _transportChannel = ChannelWrapper.WrapChannel(_transportChannel); //} if (_transportAdapter != null) { var registeredChannel = ClientTransportAdapterManager.Instance.GetTransportAdapter(_transportAdapter.UniqueName); if (registeredChannel == null) { ClientTransportAdapterManager.Instance.Register(_transportAdapter); } } else { throw new ApplicationException(LanguageResource.ApplicationException_NoChannelCreated); } string channelName = _transportAdapter.UniqueName; if (credentials != null && credentials.Count == 0) { credentials = null; } //try //{ //TODO: Generate logon request message and send it through transport channel //RemoteDispatcher.Logon(_sessionID, credentials); _sessionAgeLimit = SendLogonMessage(_sessionID, credentials); //TODO: Request registered components through transport channel //_registeredComponents = new List<ComponentInfo>(RemoteDispatcher.GetRegisteredComponents()); _registeredComponents = SendGetRegisteredComponentsMessage(); //TODO: Extract session age limit from logon response message. //_sessionAgeLimit = RemoteDispatcher.SessionAgeLimit; //} //catch (Exception ex) //{ // // unregister remoting channel // var registeredChannel = ClientTransportAdapterManager.Instance.GetTransportAdapter(channelName); // if (registeredChannel != null) // ClientTransportAdapterManager.Instance.Unregister(registeredChannel); // // dispose channel if it's disposable // var disposableChannel = registeredChannel as IDisposable; // if (disposableChannel != null) // disposableChannel.Dispose(); // throw ex.PreserveStackTrace(); //} StartKeepSessionAliveTimer(); _connections.Add(this); }