/// <summary> /// Creates a new transport channel that supports the IRegistrationChannel service contract. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel Create( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, ServiceMessageContext messageContext) { // create a UA binary channel. ITransportChannel channel = CreateUaBinaryChannel( configuration, description, endpointConfiguration, clientCertificate, messageContext); // create a WCF XML channel. if (channel == null) { Uri endpointUrl = new Uri(description.EndpointUrl); channel = new RegistrationChannel(); TransportChannelSettings settings = new TransportChannelSettings(); settings.Configuration = endpointConfiguration; settings.Description = description; settings.ClientCertificate = clientCertificate; channel.Initialize(endpointUrl, settings); } return(channel); }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, ITransportWaitingConnection connection, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, X509Certificate2Collection clientCertificateChain, ServiceMessageContext messageContext) { bool useUaTcp = description.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp); bool useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttps); // initialize the channel which will be created with the server. ITransportChannel channel = null; if (useUaTcp) { channel = new TcpTransportChannel(); } #if !NO_HTTPS else if (useHttps) { channel = new HttpsTransportChannel(); } #endif if (channel == null) { throw ServiceResultException.Create( StatusCodes.BadProtocolVersionUnsupported, "Unsupported transport profile\r\n"); } // create a UA channel. var settings = new TransportChannelSettings { Description = description, Configuration = endpointConfiguration, ClientCertificate = clientCertificate, ClientCertificateChain = clientCertificateChain }; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; channel.Initialize(connection, settings); channel.Open(); return(channel); }
/// <summary> /// Initializes a secure channel with the endpoint identified by the URL. /// </summary> /// <param name="url">The URL for the endpoint.</param> /// <param name="settings">The settings to use when creating the channel.</param> /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception> public void Initialize(Uri url, TransportChannelSettings settings) { if (m_wcfBypassChannel != null) { m_wcfBypassChannel.Initialize(url, settings); return; } throw new NotSupportedException("WCF channels must be configured when they are constructed."); }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, ITransportWaitingConnection connection, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, X509Certificate2Collection clientCertificateChain, IServiceMessageContext messageContext) { // initialize the channel which will be created with the server. string uriScheme = new Uri(description.EndpointUrl).Scheme; ITransportChannel channel = TransportBindings.Channels.GetChannel(uriScheme); if (channel == null) { throw ServiceResultException.Create( StatusCodes.BadProtocolVersionUnsupported, "Unsupported transport profile for scheme {0}.", uriScheme); } // create a UA channel. var settings = new TransportChannelSettings { Description = description, Configuration = endpointConfiguration, ClientCertificate = clientCertificate, ClientCertificateChain = clientCertificateChain }; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; channel.Initialize(connection, settings); channel.Open(); return(channel); }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="clientCertificateChain">The client certificate chain.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, X509Certificate2Collection clientCertificateChain, ServiceMessageContext messageContext) { bool useUaTcp = description.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp); bool useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttps); switch (description.TransportProfileUri) { case Profiles.UaTcpTransport: { useUaTcp = true; break; } case Profiles.HttpsBinaryTransport: { useHttps = true; break; } } // note: WCF channels are not supported if (!useUaTcp #if !NO_HTTPS && !useHttps #endif ) { throw ServiceResultException.Create( StatusCodes.BadProtocolVersionUnsupported, "Unsupported transport profile\r\n"); } // initialize the channel which will be created with the server. ITransportChannel channel = null; // create a UA-TCP channel. TransportChannelSettings settings = new TransportChannelSettings(); settings.Description = description; settings.Configuration = endpointConfiguration; settings.ClientCertificate = clientCertificate; settings.ClientCertificateChain = clientCertificateChain; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; if (useUaTcp) { if (g_CustomTransportChannel != null) { channel = g_CustomTransportChannel.Create(); } else { channel = new TcpTransportChannel(); } } else if (useHttps) { #if !NO_HTTPS channel = new HttpsTransportChannel(); #endif } channel.Initialize(new Uri(description.EndpointUrl), settings); channel.Open(); return(channel); }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, ServiceMessageContext messageContext) { // check if the server if configured to use the ANSI C stack. bool useUaTcp = description.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp); bool useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttps); #if !SILVERLIGHT bool useAnsiCStack = false; #else useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttp); #endif switch (description.TransportProfileUri) { case Profiles.UaTcpTransport: { useUaTcp = true; #if !SILVERLIGHT if (configuration != null) { useAnsiCStack = configuration.UseNativeStack; } #endif break; } case Profiles.HttpsXmlTransport: case Profiles.HttpsBinaryTransport: case Profiles.HttpsXmlOrBinaryTransport: { useHttps = true; break; } } #if !SILVERLIGHT // check for a WCF channel. if (!useUaTcp && !useHttps) { // binary channels only need the base class. if (endpointConfiguration.UseBinaryEncoding) { Uri endpointUrl = new Uri(description.EndpointUrl); BindingFactory bindingFactory = BindingFactory.Create(configuration, messageContext); Binding binding = bindingFactory.Create(endpointUrl.Scheme, description, endpointConfiguration); WcfChannelBase<IChannelBase> wcfChannel = new WcfChannelBase<IChannelBase>(); // create regular binding. if (configuration != null) { wcfChannel.Initialize( configuration, description, endpointConfiguration, binding, clientCertificate, null); } // create no-security discovery binding. else { wcfChannel.Initialize( description, endpointConfiguration, binding, null); } return wcfChannel; } return null; } #endif // initialize the channel which will be created with the server. ITransportChannel channel = null; // create a UA-TCP channel. TransportChannelSettings settings = new TransportChannelSettings(); settings.Description = description; settings.Configuration = endpointConfiguration; settings.ClientCertificate = clientCertificate; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } #if !SILVERLIGHT if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } #endif settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; if (useUaTcp) { #if !SILVERLIGHT Type type = null; if (useAnsiCStack) { type = Type.GetType("Opc.Ua.NativeStack.NativeStackChannel,Opc.Ua.NativeStackWrapper"); } if (useAnsiCStack && type != null) { channel = (ITransportChannel)Activator.CreateInstance(type); } else { channel = new Opc.Ua.Bindings.TcpTransportChannel(); } #endif } else if (useHttps) { channel = new Opc.Ua.Bindings.HttpsTransportChannel(); } channel.Initialize(new Uri(description.EndpointUrl), settings); channel.Open(); return channel; }
/// <summary> /// Initializes a secure channel with the endpoint identified by the URL. /// </summary> /// <param name="url">The URL for the endpoint.</param> /// <param name="settings">The settings to use when creating the channel.</param> /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception> public void Initialize( Uri url, TransportChannelSettings settings) { if (m_wcfBypassChannel != null) { m_wcfBypassChannel.Initialize(url, settings); return; } throw new NotSupportedException("WCF channels must be configured when they are constructed."); }
/// <summary> /// Initializes a secure channel with the endpoint identified by the URL. /// </summary> /// <param name="connection">The connection to use.</param> /// <param name="settings">The settings to use when creating the channel.</param> /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception> public void Initialize( ITransportWaitingConnection connection, TransportChannelSettings settings) { throw new NotSupportedException("WCF channels must be configured when they are constructed."); }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, ServiceMessageContext messageContext) { // check if the server if configured to use the ANSI C stack. bool useUaTcp = description.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp); bool useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttps); bool useAnsiCStack = false; switch (description.TransportProfileUri) { case Profiles.UaTcpTransport: { useUaTcp = true; if (configuration != null) { useAnsiCStack = configuration.UseNativeStack; } break; } case Profiles.HttpsXmlTransport: case Profiles.HttpsBinaryTransport: case Profiles.HttpsXmlOrBinaryTransport: { useHttps = true; break; } } // note: WCF channels are not supported if (!useUaTcp && !useHttps) { throw ServiceResultException.Create( StatusCodes.BadServiceUnsupported, "Unsupported transport profile\r\n"); } // initialize the channel which will be created with the server. ITransportChannel channel = null; // create a UA-TCP channel. TransportChannelSettings settings = new TransportChannelSettings(); settings.Description = description; settings.Configuration = endpointConfiguration; settings.ClientCertificate = clientCertificate; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; if (useUaTcp) { Type type = null; if (useAnsiCStack) { type = Type.GetType("Opc.Ua.NativeStack.NativeStackChannel,Opc.Ua.NativeStackWrapper"); } if (useAnsiCStack && type != null) { channel = (ITransportChannel)Activator.CreateInstance(type); } else { channel = new Opc.Ua.Bindings.TcpTransportChannel(); } } else if (useHttps) { channel = new Opc.Ua.Bindings.HttpsTransportChannel(); } channel.Initialize(new Uri(description.EndpointUrl), settings); channel.Open(); return(channel); }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, ServiceMessageContext messageContext) { // check if the server if configured to use the ANSI C stack. bool useUaTcp = description.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp); bool useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttps); bool useAnsiCStack = false; switch (description.TransportProfileUri) { case Profiles.UaTcpTransport: { useUaTcp = true; if (configuration != null) { useAnsiCStack = configuration.UseNativeStack; } break; } case Profiles.HttpsXmlTransport: case Profiles.HttpsBinaryTransport: case Profiles.HttpsXmlOrBinaryTransport: { useHttps = true; break; } } // note: WCF channels are not supported if (!useUaTcp && !useHttps) { throw ServiceResultException.Create( StatusCodes.BadServiceUnsupported, "Unsupported transport profile\r\n"); } // initialize the channel which will be created with the server. ITransportChannel channel = null; // create a UA-TCP channel. TransportChannelSettings settings = new TransportChannelSettings(); settings.Description = description; settings.Configuration = endpointConfiguration; settings.ClientCertificate = clientCertificate; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; if (useUaTcp) { Type type = null; if (useAnsiCStack) { type = Type.GetType("Opc.Ua.NativeStack.NativeStackChannel,Opc.Ua.NativeStackWrapper"); } if (useAnsiCStack && type != null) { channel = (ITransportChannel)Activator.CreateInstance(type); } else { channel = new Opc.Ua.Bindings.TcpTransportChannel(); } } else if (useHttps) { channel = new Opc.Ua.Bindings.HttpsTransportChannel(); } channel.Initialize(new Uri(description.EndpointUrl), settings); channel.Open(); return channel; }
/// <summary> /// Creates a new transport channel that supports the IRegistrationChannel service contract. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel Create( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, ServiceMessageContext messageContext) { // create a UA binary channel. ITransportChannel channel = CreateUaBinaryChannel( configuration, description, endpointConfiguration, clientCertificate, messageContext); // create a WCF XML channel. if (channel == null) { Uri endpointUrl = new Uri(description.EndpointUrl); channel = new RegistrationChannel(); TransportChannelSettings settings = new TransportChannelSettings(); settings.Configuration = endpointConfiguration; settings.Description = description; settings.ClientCertificate = clientCertificate; channel.Initialize(endpointUrl, settings); } return channel; }
/// <summary> /// Creates a new UA-binary transport channel if requested. Null otherwise. /// </summary> /// <param name="configuration">The application configuration.</param> /// <param name="description">The description for the endpoint.</param> /// <param name="endpointConfiguration">The configuration to use with the endpoint.</param> /// <param name="clientCertificate">The client certificate.</param> /// <param name="messageContext">The message context to use when serializing the messages.</param> /// <returns></returns> public static ITransportChannel CreateUaBinaryChannel( ApplicationConfiguration configuration, EndpointDescription description, EndpointConfiguration endpointConfiguration, X509Certificate2 clientCertificate, ServiceMessageContext messageContext) { bool useUaTcp = description.EndpointUrl.StartsWith(Utils.UriSchemeOpcTcp); bool useHttps = description.EndpointUrl.StartsWith(Utils.UriSchemeHttps); switch (description.TransportProfileUri) { case Profiles.UaTcpTransport: { useUaTcp = true; break; } case Profiles.HttpsBinaryTransport: { useHttps = true; break; } } // note: WCF channels are not supported if (!useUaTcp && !useHttps) { throw ServiceResultException.Create( StatusCodes.BadServiceUnsupported, "Unsupported transport profile\r\n"); } // initialize the channel which will be created with the server. ITransportChannel channel = null; // create a UA-TCP channel. TransportChannelSettings settings = new TransportChannelSettings(); settings.Description = description; settings.Configuration = endpointConfiguration; settings.ClientCertificate = clientCertificate; if (description.ServerCertificate != null && description.ServerCertificate.Length > 0) { settings.ServerCertificate = Utils.ParseCertificateBlob(description.ServerCertificate); } if (configuration != null) { settings.CertificateValidator = configuration.CertificateValidator.GetChannelValidator(); } settings.NamespaceUris = messageContext.NamespaceUris; settings.Factory = messageContext.Factory; if (useUaTcp) { if (g_CustomTransportChannel != null) { channel = g_CustomTransportChannel.Create(); } else { channel = new TcpTransportChannel(); } } else if (useHttps) { channel = new HttpsTransportChannel(); } channel.Initialize(new Uri(description.EndpointUrl), settings); channel.Open(); return channel; }