public void ToVersioned() { var input = new ProtocolInformation(new Version(1, 2, 3, 4), new Uri("http://localhost/protocol/invalid")); var output = ChannelInformationToTransportConverter.ToVersioned(input); Assert.AreSame(input.Version, output.ProtocolVersion); Assert.AreSame(input.MessageAddress, output.Address); }
public void FromVersioned() { var input = new VersionedChannelInformation { ProtocolVersion = new Version(1, 2, 3, 4), Address = new Uri("http://localhost/invalid") }; var output = ChannelInformationToTransportConverter.FromVersioned(input); Assert.AreSame(input.ProtocolVersion, output.Version); Assert.AreSame(input.Address, output.MessageAddress); }
/// <summary> /// Returns the discovery information for the communication protocol with the given version. /// </summary> /// <param name="version">The version of the protocol for which the discovery information should be provided.</param> /// <returns>The discovery information for the communication protocol with the given version.</returns> public VersionedChannelInformation ConnectionInformationForProtocol(Version version) { if (version == null) { return(null); } if (!m_ProtocolInformation.ContainsKey(version)) { return(null); } var info = m_ProtocolInformation[version]; return(ChannelInformationToTransportConverter.ToVersioned(info)); }
/// <summary> /// Returns channel information obtained from a specific versioned discovery channel. /// </summary> /// <param name="versionSpecificDiscoveryAddress">The address of the versioned discovery channel.</param> /// <returns>The information describing the protocol channel used by the remote endpoint.</returns> public ProtocolInformation FromUri(Uri versionSpecificDiscoveryAddress) { var factory = CreateFactoryForDiscoveryChannel(versionSpecificDiscoveryAddress); var service = factory.CreateChannel(); var channel = (IChannel)service; try { var serviceVersion = service.Version(); if (serviceVersion != DiscoveryVersions.V1) { throw new IncorrectTranslatorVersionException(); } var versions = service.ProtocolVersions(); var intersection = versions .Intersect(m_ProtocolVersions) .OrderByDescending(v => v); if (!intersection.Any()) { return(null); } var highestVersion = intersection.First(); var localInfo = service.ConnectionInformationForProtocol(highestVersion); return(ChannelInformationToTransportConverter.FromVersioned(localInfo)); } catch (FaultException e) { m_Diagnostics.Log( LevelToLog.Warn, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, Resources.Log_Messages_DiscoveryFailedToConnectToEndpoint_WithUriAndError, versionSpecificDiscoveryAddress, e)); } catch (CommunicationException e) { m_Diagnostics.Log( LevelToLog.Warn, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, Resources.Log_Messages_DiscoveryFailedToConnectToEndpoint_WithUriAndError, versionSpecificDiscoveryAddress, e)); } finally { try { channel.Close(); } catch (CommunicationObjectFaultedException e) { // The default close timeout elapsed before we were // finished closing the channel. So the channel // is aborted. Nothing we can do, just ignore it. m_Diagnostics.Log( LevelToLog.Debug, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Channel for {0} failed to close normally. Exception was: {1}", factory.Endpoint.Address.Uri, e)); } catch (ProtocolException e) { // The default close timeout elapsed before we were // finished closing the channel. So the channel // is aborted. Nothing we can do, just ignore it. m_Diagnostics.Log( LevelToLog.Debug, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Channel for {0} failed to close normally. Exception was: {1}", factory.Endpoint.Address.Uri, e)); } catch (CommunicationObjectAbortedException e) { // The default close timeout elapsed before we were // finished closing the channel. So the channel // is aborted. Nothing we can do, just ignore it. m_Diagnostics.Log( LevelToLog.Debug, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Channel for {0} failed to close normally. Exception was: {1}", factory.Endpoint.Address.Uri, e)); } catch (TimeoutException e) { // The default close timeout elapsed before we were // finished closing the channel. So the channel // is aborted. Nothing we can do, just ignore it. m_Diagnostics.Log( LevelToLog.Debug, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Channel for {0} failed to close normally. Exception was: {1}", factory.Endpoint.Address.Uri, e)); } } return(null); }
public void FromVersionedWithNullObject() { Assert.Throws <ArgumentNullException>(() => ChannelInformationToTransportConverter.FromVersioned(null)); }