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 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)); }