mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-29 07:07:24 +08:00
- Implement the reconnect and republish with async service calls. bug fixes: - subscription Ids should start from a random number - the keep alive interval calculation is too short, adding +1 for the timeout - on BadSessionIdInvalid recreate session immediately - on a restarted server with new certificate, also reload endpoints when BadCertificateInvalid is returned
202 lines
11 KiB
C#
202 lines
11 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2022 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Opc.Ua.Client
|
|
{
|
|
/// <summary>
|
|
/// Object that creates instances of an ISessions object.
|
|
/// </summary>
|
|
public interface ISessionFactory
|
|
{
|
|
/// <summary>
|
|
/// Creates a new communication session with a server by invoking the CreateSession service
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration for the client application.</param>
|
|
/// <param name="endpoint">The endpoint for the server.</param>
|
|
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
|
|
/// <param name="sessionName">The name to assign to the session.</param>
|
|
/// <param name="sessionTimeout">The timeout period for the session.</param>
|
|
/// <param name="identity">The identity.</param>
|
|
/// <param name="preferredLocales">The user identity to associate with the session.</param>
|
|
/// <param name="ct">The cancellation token</param>
|
|
/// <returns>The new session object</returns>
|
|
Task<ISession> CreateAsync(
|
|
ApplicationConfiguration configuration,
|
|
ConfiguredEndpoint endpoint,
|
|
bool updateBeforeConnect,
|
|
string sessionName,
|
|
uint sessionTimeout,
|
|
IUserIdentity identity,
|
|
IList<string> preferredLocales,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Creates a new communication session with a server by invoking the CreateSession service
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration for the client application.</param>
|
|
/// <param name="endpoint">The endpoint for the server.</param>
|
|
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
|
|
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate must match the endpoint used.</param>
|
|
/// <param name="sessionName">The name to assign to the session.</param>
|
|
/// <param name="sessionTimeout">The timeout period for the session.</param>
|
|
/// <param name="identity">The user identity to associate with the session.</param>
|
|
/// <param name="preferredLocales">The preferred locales.</param>
|
|
/// <param name="ct">The cancellation token</param>
|
|
/// <returns>The new session object.</returns>
|
|
Task<ISession> CreateAsync(
|
|
ApplicationConfiguration configuration,
|
|
ConfiguredEndpoint endpoint,
|
|
bool updateBeforeConnect,
|
|
bool checkDomain,
|
|
string sessionName,
|
|
uint sessionTimeout,
|
|
IUserIdentity identity,
|
|
IList<string> preferredLocales,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Creates a new session with a server using the specified channel by invoking the CreateSession service.
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration for the client application.</param>
|
|
/// <param name="channel">The channel for the server.</param>
|
|
/// <param name="endpoint">The endpoint for the server.</param>
|
|
/// <param name="clientCertificate">The certificate to use for the client.</param>
|
|
/// <param name="availableEndpoints">The list of available endpoints returned by server in GetEndpoints() response.</param>
|
|
/// <param name="discoveryProfileUris">The value of profileUris used in GetEndpoints() request.</param>
|
|
ISession Create(
|
|
ApplicationConfiguration configuration,
|
|
ITransportChannel channel,
|
|
ConfiguredEndpoint endpoint,
|
|
X509Certificate2 clientCertificate,
|
|
EndpointDescriptionCollection availableEndpoints = null,
|
|
StringCollection discoveryProfileUris = null);
|
|
|
|
/// <summary>
|
|
/// Creates a secure channel to the specified endpoint.
|
|
/// </summary>
|
|
/// <param name="configuration">The application configuration.</param>
|
|
/// <param name="connection">The client endpoint for the reverse connect.</param>
|
|
/// <param name="endpoint">A configured endpoint to connect to.</param>
|
|
/// <param name="updateBeforeConnect">Update configuration based on server prior connect.</param>
|
|
/// <param name="checkDomain">Check that the certificate specifies a valid domain (computer) name.</param>
|
|
/// <param name="ct">The cancellation token.</param>
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
Task<ITransportChannel> CreateChannelAsync(
|
|
ApplicationConfiguration configuration,
|
|
ITransportWaitingConnection connection,
|
|
ConfiguredEndpoint endpoint,
|
|
bool updateBeforeConnect,
|
|
bool checkDomain,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Creates a new communication session with a server using a reverse connection.
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration for the client application.</param>
|
|
/// <param name="connection">The client endpoint for the reverse connect.</param>
|
|
/// <param name="endpoint">The endpoint for the server.</param>
|
|
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
|
|
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate must match the endpoint used.</param>
|
|
/// <param name="sessionName">The name to assign to the session.</param>
|
|
/// <param name="sessionTimeout">The timeout period for the session.</param>
|
|
/// <param name="identity">The user identity to associate with the session.</param>
|
|
/// <param name="preferredLocales">The preferred locales.</param>
|
|
/// <param name="ct">The cancellation token</param>
|
|
/// <returns>The new session object.</returns>
|
|
Task<ISession> CreateAsync(
|
|
ApplicationConfiguration configuration,
|
|
ITransportWaitingConnection connection,
|
|
ConfiguredEndpoint endpoint,
|
|
bool updateBeforeConnect,
|
|
bool checkDomain,
|
|
string sessionName,
|
|
uint sessionTimeout,
|
|
IUserIdentity identity,
|
|
IList<string> preferredLocales,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Creates a new communication session with a server using a reverse connect manager.
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration for the client application.</param>
|
|
/// <param name="reverseConnectManager">The reverse connect manager for the client connection.</param>
|
|
/// <param name="endpoint">The endpoint for the server.</param>
|
|
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used to update the endpoint description before connecting.</param>
|
|
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate must match the endpoint used.</param>
|
|
/// <param name="sessionName">The name to assign to the session.</param>
|
|
/// <param name="sessionTimeout">The timeout period for the session.</param>
|
|
/// <param name="userIdentity">The user identity to associate with the session.</param>
|
|
/// <param name="preferredLocales">The preferred locales.</param>
|
|
/// <param name="ct">The cancellation token.</param>
|
|
/// <returns>The new session object.</returns>
|
|
Task<ISession> CreateAsync(
|
|
ApplicationConfiguration configuration,
|
|
ReverseConnectManager reverseConnectManager,
|
|
ConfiguredEndpoint endpoint,
|
|
bool updateBeforeConnect,
|
|
bool checkDomain,
|
|
string sessionName,
|
|
uint sessionTimeout,
|
|
IUserIdentity userIdentity,
|
|
IList<string> preferredLocales,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Recreates a session based on a specified template.
|
|
/// </summary>
|
|
/// <param name="sessionTemplate">The ISession object to use as template</param>
|
|
/// <param name="ct">The cancellation token.</param>
|
|
/// <returns>The new session object.</returns>
|
|
Task<ISession> RecreateAsync(ISession sessionTemplate, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Recreates a session based on a specified template.
|
|
/// </summary>
|
|
/// <param name="sessionTemplate">The ISession object to use as template</param>
|
|
/// <param name="connection">The waiting reverse connection.</param>
|
|
/// <param name="ct">The cancellation token.</param>
|
|
/// <returns>The new session object.</returns>
|
|
Task<ISession> RecreateAsync(ISession sessionTemplate, ITransportWaitingConnection connection, CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// Recreates a session based on a specified template using the provided channel.
|
|
/// </summary>
|
|
/// <param name="sessionTemplate">The Session object to use as template</param>
|
|
/// <param name="transportChannel">The channel to use to recreate the session.</param>
|
|
/// <param name="ct">The cancellation token.</param>
|
|
/// <returns>The new session object.</returns>
|
|
Task<ISession> RecreateAsync(ISession sessionTemplate, ITransportChannel transportChannel, CancellationToken ct = default);
|
|
}
|
|
}
|