From 9bda2a2409ee0402b2a286bbcc35f040d79c0254 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:13:10 +0000 Subject: [PATCH 1/4] Initial plan From d7744c47bb6f79cdb29cad9cecdef5153c5115f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:27:22 +0000 Subject: [PATCH 2/4] Add WCF Faulted EventHandler for automatic recovery from communication faults - Added Faulted event handlers for all 19 service channels in InfoShareWcfSoapWithOpenIdConnectConnection - Added Faulted event handlers for all 19 service channels in InfoShareWcfSoapWithWsTrustConnection - Registered event handlers after client creation in both NET48 and NET60+ code paths - Event handlers call Abort() on faulted channels and set clients to null for automatic recreation - Added debug logging to track CommunicationState when recreating clients - Removed known issue about faulted communication objects from README.MD Co-authored-by: ddemeyer <19798225+ddemeyer@users.noreply.github.com> --- README.MD | 5 +- ...ShareWcfSoapWithOpenIdConnectConnection.cs | 3109 +++++++++-------- .../InfoShareWcfSoapWithWsTrustConnection.cs | 268 ++ 3 files changed, 1968 insertions(+), 1414 deletions(-) diff --git a/README.MD b/README.MD index c56ba4c0..fbdb5c6c 100644 --- a/README.MD +++ b/README.MD @@ -65,10 +65,7 @@ Any feedback is welcome. Please log a GitHub issue, make sure you submit your ve * If a `New-IshSession -IshUserName ...` results in `System.ServiceModel.FaultException` followed by `An error occurred when verifying security for the message.`, then you are using `-Protocol WcfSoapWithWsTrust` implicitly. A very likely candidate is that deprecated `/ISHSTS/` which authenticates the WS-Federation protocol was not part of your certificate rollover. A simple workaround is to stop the ISHSTS IIS App Pool, delete `\Web\InfoShareSTS\App_Data\IdentityServerConfiguration-2.3.sdf` and in turn start the IIS App Pool again - which will regenerate the local .sdf database. * If you get `You cannot call a method on a null-valued expression.` or `The HTTP status code of the response was not expected (401).`, probably while using `$ishSession.OpenApiISH30Client` it means your token expired and requires a refresh. * If you get `New-IshSession : Reference to undeclared entity 'raquo'. Line 98, position 121.`, most likely you specified an unexisting "Web Services API" url. Make sure your url ends with an ending slash `/`. -* If a test fails with `The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.`, - it probably means you didn't provide enough (mandatory) parameters to the WCF/SVC code so passing null parameters. Typically an `-IshPassword` is missing or using an existing username. -* ISHDeploy `Enable-ISHIntegrationSTSInternalAuthentication/Disable-ISHIntegrationSTSInternalAuthentication` adds a /ISHWS/Internal/connectionconfiguration.xml that a different issuer should be used. As ISHRemote doesn't have an app.config, all the artifacts are derived from the RelyingParty WSDL provided mex endpoint (e.g. /ISHSTS/issue/wstrust/mex). -If you get error `New-IshSession : The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.`, it probably means you initialized `-WsBaseUrl` without the `/Internal/` (or `/SDL/`) segment, meaning you are using the primary configured STS. +* ISHDeploy `Enable-ISHIntegrationSTSInternalAuthentication/Disable-ISHIntegrationSTSInternalAuthentication` adds a /ISHWS/Internal/connectionconfiguration.xml that a different issuer should be used. As ISHRemote doesn't have an app.config, all the artifacts are derived from the RelyingParty WSDL provided mex endpoint (e.g. /ISHSTS/issue/wstrust/mex). # Standards To Respect diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs index b4cb8a8a..749dabad 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs @@ -1,1410 +1,1699 @@ -/* -* Copyright (c) 2014 All Rights Reserved by the SDL Group. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -using System; -using System.Collections.Generic; -using System.IdentityModel.Tokens; -using System.Net.Http; -using System.ServiceModel; -using System.Xml.Linq; -using Trisoft.ISHRemote.Interfaces; -using System.ServiceModel.Security; -using System.Security.Cryptography.X509Certificates; -using System.Net; -using System.Net.Http.Headers; -using System.Security.Claims; -using System.Text; -using System.Xml; -using System.IO; - -#if !NET48 -using System.ServiceModel.Federation; -#endif - -namespace Trisoft.ISHRemote.Connection -{ - /// - /// Dynamic proxy (so without app.config) generation of Service References towards the InfoShare Web Services writen in Windows Communication Foundation (WCF) protected by OpenIdConnect security protocol. - /// On ISHRemote v1 and earlier, so in turn before InfoShare 15 and earlier, this class was your starting point for dynamic proxy (so without app.config) generation of Service References. The inital class was written in .NET Framework style. Inspired by https://devblogs.microsoft.com/dotnet/wsfederationhttpbinding-in-net-standard-wcf/ this class has pragmas to illustrate .NET Framework and .NET 6.0+ style side-by-side. - /// - internal sealed class InfoShareWcfSoapWithOpenIdConnectConnection : InfoShareOpenIdConnectConnectionBase, IDisposable - { - #region Constants - /// - /// Annotation25 - /// - private const string Annotation25 = "Annotation25"; - /// - /// Application25 - /// - private const string Application25 = "Application25"; - /// - /// DocumentObj25 - /// - private const string DocumentObj25 = "DocumentObj25"; - /// - /// Folder25 - /// - private const string Folder25 = "Folder25"; - /// - /// User25 - /// - private const string User25 = "User25"; - /// - /// UserRole25 - /// - private const string UserRole25 = "UserRole25"; - /// - /// UserGroup25 - /// - private const string UserGroup25 = "UserGroup25"; - /// - /// ListOfValues25 - /// - private const string ListOfValues25 = "ListOfValues25"; - /// - /// PublicationOutput25 - /// - private const string PublicationOutput25 = "PublicationOutput25"; - /// - /// OutputFormat25 - /// - private const string OutputFormat25 = "OutputFormat25"; - /// - /// Settings25 - /// - private const string Settings25 = "Settings25"; - /// - /// EDT25 - /// - private const string EDT25 = "EDT25"; - /// - /// EventMonitor25 - /// - private const string EventMonitor25 = "EventMonitor25"; - /// - /// Baseline25 - /// - private const string Baseline25 = "Baseline25"; - /// - /// MetadataBinding25 - /// - private const string MetadataBinding25 = "MetadataBinding25"; - /// - /// Search25 - /// - private const string Search25 = "Search25"; - /// - /// TranslationJob25 - /// - private const string TranslationJob25 = "TranslationJob25"; - /// - /// TranslationTemplate25 - /// - private const string TranslationTemplate25 = "TranslationTemplate25"; - /// - /// BackgroundTask25 - /// - private const string BackgroundTask25 = "BackgroundTask25"; - #endregion - - #region Private Members - /// - /// Service URIs by service. - /// - private readonly Dictionary _serviceUriByServiceName = new Dictionary(); -#if NET48 - /// - /// Binding that is common for every endpoint. - /// - private readonly WS2007FederationHttpBinding _commonBinding; -#else - /// - /// Binding that is common for every endpoint. - /// - private readonly WSFederationHttpBinding _commonBinding; -#endif - - /// - /// Proxy for annotation - /// - private Annotation25ServiceReference.AnnotationClient _annotationClient; - private Annotation25ServiceReference.Annotation _annotationServiceReference; - /// - /// Proxy for application - /// - private Application25ServiceReference.ApplicationClient _applicationClient; - private Application25ServiceReference.Application _applicationServiceReference; - /// - /// Proxy for document obj - /// - private DocumentObj25ServiceReference.DocumentObjClient _documentObjClient; - private DocumentObj25ServiceReference.DocumentObj _documentObjServiceReference; - /// - /// Proxy for folder - /// - private Folder25ServiceReference.FolderClient _folderClient; - private Folder25ServiceReference.Folder _folderServiceReference; - /// - /// Proxy for user - /// - private User25ServiceReference.UserClient _userClient; - private User25ServiceReference.User _userServiceReference; - /// - /// Proxy for user role - /// - private UserRole25ServiceReference.UserRoleClient _userRoleClient; - private UserRole25ServiceReference.UserRole _userRoleServiceReference; - /// - /// Proxy for user group - /// - private UserGroup25ServiceReference.UserGroupClient _userGroupClient; - private UserGroup25ServiceReference.UserGroup _userGroupServiceReference; - /// - /// Proxy for LOV - /// - private ListOfValues25ServiceReference.ListOfValuesClient _listOfValuesClient; - private ListOfValues25ServiceReference.ListOfValues _listOfValuesServiceReference; - /// - /// Proxy for publication output - /// - private PublicationOutput25ServiceReference.PublicationOutputClient _publicationOutputClient; - private PublicationOutput25ServiceReference.PublicationOutput _publicationOutputServiceReference; - /// - /// Proxy for output format - /// - private OutputFormat25ServiceReference.OutputFormatClient _outputFormatClient; - private OutputFormat25ServiceReference.OutputFormat _outputFormatServiceReference; - /// - /// Proxy for settings - /// - private Settings25ServiceReference.SettingsClient _settingsClient; - private Settings25ServiceReference.Settings _settingsServiceReference; - /// - /// Proxy for EDT - /// - private EDT25ServiceReference.EDTClient _EDTClient; - private EDT25ServiceReference.EDT _EDTServiceReference; - /// - /// Proxy for event monitor - /// - private EventMonitor25ServiceReference.EventMonitorClient _eventMonitorClient; - private EventMonitor25ServiceReference.EventMonitor _eventMonitorServiceReference; - /// - /// Proxy for baseline - /// - private Baseline25ServiceReference.BaselineClient _baselineClient; - private Baseline25ServiceReference.Baseline _baselineServiceReference; - /// - /// Proxy for metadata binding - /// - private MetadataBinding25ServiceReference.MetadataBindingClient _metadataBindingClient; - private MetadataBinding25ServiceReference.MetadataBinding _metadataBindingServiceReference; - /// - /// Proxy for search - /// - private Search25ServiceReference.SearchClient _searchClient; - private Search25ServiceReference.Search _searchServiceReference; - /// - /// Proxy for translation job - /// - private TranslationJob25ServiceReference.TranslationJobClient _translationJobClient; - private TranslationJob25ServiceReference.TranslationJob _translationJobServiceReference; - /// - /// Proxy for translation template - /// - private TranslationTemplate25ServiceReference.TranslationTemplateClient _translationTemplateClient; - private TranslationTemplate25ServiceReference.TranslationTemplate _translationTemplateServiceReference; - /// - /// Proxy for background task - /// - private BackgroundTask25ServiceReference.BackgroundTaskClient _backgroundTaskClient; - private BackgroundTask25ServiceReference.BackgroundTask _backgroundTaskServiceReference; - #endregion Private Members - - #region Constructors - /// - /// Initializes a new instance of InfoShareWcfSoapWithOpenIdConnectConnection class. - /// - /// Instance of Interfaces.ILogger implementation - /// Incoming reused, probably Ssl/Tls initialized already. - /// OpenIdConnect connection parameters to be shared with WcfSoapWithOpenIdConnect and OpenApiWithOpenIdConnect - public InfoShareWcfSoapWithOpenIdConnectConnection(ILogger logger, HttpClient httpClient, InfoShareOpenIdConnectConnectionParameters infoShareOpenIdConnectConnectionParameters) - : base(logger, httpClient, infoShareOpenIdConnectConnectionParameters) - { - _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection InfoShareWSUrl[{_connectionParameters.InfoShareWSUrl}]"); - if (_connectionParameters.Tokens == null) - { - if ((string.IsNullOrEmpty(_connectionParameters.ClientId)) && (string.IsNullOrEmpty(_connectionParameters.ClientSecret))) - { - // attempt System Browser retrieval of Access/Bearer Token - _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection System Browser"); - _connectionParameters.Tokens = GetTokensOverSystemBrowserAsync().GetAwaiter().GetResult(); - } - else if ((!string.IsNullOrEmpty(_connectionParameters.ClientId)) && (!string.IsNullOrEmpty(_connectionParameters.ClientSecret))) - { - // Raw method without OidcClient, see GetTokensOverClientCredentialsRaw(); - _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection ClientId[{_connectionParameters.ClientId}] ClientSecret[{new string('*', _connectionParameters.ClientSecret.Length)}]"); - _connectionParameters.Tokens = GetTokensOverClientCredentialsAsync().GetAwaiter().GetResult(); - } - else - { - throw new ArgumentException("Expected ClientId and ClientSecret to be not null or empty."); - } - } - else - { - // Don't think this will happen - _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection reusing AccessToken[{_connectionParameters.Tokens.AccessToken}] AccessTokenExpiration[{_connectionParameters.Tokens.AccessTokenExpiration}]"); - } - _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection Access Token received ValidTo[{_connectionParameters.Tokens.AccessTokenExpiration.ToString("yyyyMMdd.HHmmss.fff")}]"); - _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _connectionParameters.Tokens.AccessToken); - // using the ISHWS url from connectionconfiguration.xml instead of the potentially wrongly cased incoming one [TS-10630] - _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection using Normalized infoShareWSBaseUri[{_connectionParameters.InfoShareWSUrl}]"); - this.InfoShareWSBaseUri = _connectionParameters.InfoShareWSUrl; - - _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection Resolving Service Uris"); - ResolveServiceUris(); - -#if NET48 - _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Resolving Binding (NET48)"); - _commonBinding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential); - _commonBinding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey; - _commonBinding.Security.Message.IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0"; -#else - _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Resolving Binding (NET6+)"); - _commonBinding = new WSFederationHttpBinding(new WSTrustTokenParameters - { - TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0", - KeyType = SecurityKeyType.BearerKey - }); -#endif - _commonBinding.Security.Message.EstablishSecurityContext = false; - _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Binding Text ReaderQuotas"); - _commonBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; - _commonBinding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue; - _commonBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; - _commonBinding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue; - _commonBinding.ReaderQuotas.MaxDepth = 64; - _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Binding Transport Quotas"); - _commonBinding.MaxReceivedMessageSize = Int32.MaxValue; - _commonBinding.MaxBufferPoolSize = Int32.MaxValue; - _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Binding Send/Receive Timeouts"); - _commonBinding.SendTimeout = _connectionParameters.IssueTimeout; - _commonBinding.ReceiveTimeout = _connectionParameters.IssueTimeout; - } - #endregion - - #region Public Properties - /// - /// Root uri for the Web Services - /// - public Uri InfoShareWSBaseUri { get; private set; } - #endregion Public Properties - - #region Public Get..Channel Methods - /// - /// Create a /Wcf/API25/Annotation.svc proxy - /// - /// The proxy - public Annotation25ServiceReference.Annotation GetAnnotation25Channel() - { -#if NET48 - if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_annotationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_annotationClient)?.Dispose(); - ((IDisposable)_annotationServiceReference)?.Dispose(); - _annotationClient = new Annotation25ServiceReference.AnnotationClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Annotation25])); - _annotationServiceReference = _annotationClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _annotationServiceReference; -#else - if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_annotationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_annotationClient)?.Dispose(); - ((IDisposable)_annotationServiceReference)?.Dispose(); - _annotationClient = new Annotation25ServiceReference.AnnotationClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Annotation25])); - - _annotationClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_annotationClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _annotationClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _annotationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _annotationClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _annotationServiceReference = _annotationClient.ChannelFactory.CreateChannel(); - } - return _annotationServiceReference; -#endif - } - /// - /// Create a /Wcf/API25/Application.svc proxy - /// - /// The proxy - public Application25ServiceReference.Application GetApplication25Channel() - { -#if NET48 - if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_applicationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_applicationClient)?.Dispose(); - ((IDisposable)_applicationServiceReference)?.Dispose(); - _applicationClient = new Application25ServiceReference.ApplicationClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Application25])); - _applicationServiceReference = _applicationClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _applicationServiceReference; -#else - if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_applicationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_applicationClient)?.Dispose(); - ((IDisposable)_applicationServiceReference)?.Dispose(); - _applicationClient = new Application25ServiceReference.ApplicationClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Application25])); - - _applicationClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_applicationClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _applicationClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _applicationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _applicationClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _applicationServiceReference = _applicationClient.ChannelFactory.CreateChannel(); - } - return _applicationServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/DocumentObj.svc proxy - /// - /// The proxy - public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() - { -#if NET48 - if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_documentObjServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_documentObjClient)?.Dispose(); - ((IDisposable)_documentObjServiceReference)?.Dispose(); - _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); - _documentObjServiceReference = _documentObjClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _documentObjServiceReference; -#else - if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_documentObjServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_documentObjClient)?.Dispose(); - ((IDisposable)_documentObjServiceReference)?.Dispose(); - _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); - - _documentObjClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_documentObjClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _documentObjClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _documentObjClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _documentObjClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _documentObjServiceReference = _documentObjClient.ChannelFactory.CreateChannel(); - } - return _documentObjServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/Folder.svc proxy - /// - /// The proxy - public Folder25ServiceReference.Folder GetFolder25Channel() - { -#if NET48 - if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_folderServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_folderClient)?.Dispose(); - ((IDisposable)_folderServiceReference)?.Dispose(); - _folderClient = new Folder25ServiceReference.FolderClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Folder25])); - _folderServiceReference = _folderClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _folderServiceReference; -#else - if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_folderServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_folderClient)?.Dispose(); - ((IDisposable)_folderServiceReference)?.Dispose(); - _folderClient = new Folder25ServiceReference.FolderClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Folder25])); - - _folderClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_folderClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _folderClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _folderClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _folderClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _folderServiceReference = _folderClient.ChannelFactory.CreateChannel(); - } - return _folderServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/User.svc proxy - /// - /// The proxy - public User25ServiceReference.User GetUser25Channel() - { -#if NET48 - if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_userServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_userClient)?.Dispose(); - ((IDisposable)_userServiceReference)?.Dispose(); - _userClient = new User25ServiceReference.UserClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[User25])); - _userServiceReference = _userClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _userServiceReference; -#else - if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_userServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_userClient)?.Dispose(); - ((IDisposable)_userServiceReference)?.Dispose(); - _userClient = new User25ServiceReference.UserClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[User25])); - - _userClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _userClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _userClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _userClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _userServiceReference = _userClient.ChannelFactory.CreateChannel(); - } - return _userServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/UserRole.svc proxy - /// - /// The proxy - public UserRole25ServiceReference.UserRole GetUserRole25Channel() - { -#if NET48 - if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_userRoleServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_userRoleClient)?.Dispose(); - ((IDisposable)_userRoleServiceReference)?.Dispose(); - _userRoleClient = new UserRole25ServiceReference.UserRoleClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[UserRole25])); - _userRoleServiceReference = _userRoleClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _userRoleServiceReference; -#else - if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_userRoleServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_userRoleClient)?.Dispose(); - ((IDisposable)_userRoleServiceReference)?.Dispose(); - _userRoleClient = new UserRole25ServiceReference.UserRoleClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[UserRole25])); - - _userRoleClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userRoleClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _userRoleClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _userRoleClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _userRoleClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _userRoleServiceReference = _userRoleClient.ChannelFactory.CreateChannel(); - } - return _userRoleServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/UserGroup.svc proxy - /// - /// The proxy - public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() - { -#if NET48 - if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_userGroupServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_userGroupClient)?.Dispose(); - ((IDisposable)_userGroupServiceReference)?.Dispose(); - _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[UserGroup25])); - _userGroupServiceReference = _userGroupClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _userGroupServiceReference; -#else - if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_userGroupServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_userGroupClient)?.Dispose(); - ((IDisposable)_userGroupServiceReference)?.Dispose(); - _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[UserGroup25])); - - _userGroupClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userGroupClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _userGroupClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _userGroupClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _userGroupClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _userGroupServiceReference = _userGroupClient.ChannelFactory.CreateChannel(); - } - return _userGroupServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/ListOfValues.svc proxy - /// - /// The proxy - public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() - { -#if NET48 - if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_listOfValuesServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_listOfValuesClient)?.Dispose(); - ((IDisposable)_listOfValuesServiceReference)?.Dispose(); - _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); - _listOfValuesServiceReference = _listOfValuesClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _listOfValuesServiceReference; -#else - if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_listOfValuesServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_listOfValuesClient)?.Dispose(); - ((IDisposable)_listOfValuesServiceReference)?.Dispose(); - _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); - - _listOfValuesClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_listOfValuesClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _listOfValuesClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _listOfValuesClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _listOfValuesClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _listOfValuesServiceReference = _listOfValuesClient.ChannelFactory.CreateChannel(); - } - return _listOfValuesServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/PublicationOutput.svc proxy - /// - /// The proxy - public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutput25Channel() - { -#if NET48 - if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_publicationOutputServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_publicationOutputClient)?.Dispose(); - ((IDisposable)_publicationOutputServiceReference)?.Dispose(); - _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); - _publicationOutputServiceReference = _publicationOutputClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _publicationOutputServiceReference; -#else - if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_publicationOutputServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_publicationOutputClient)?.Dispose(); - ((IDisposable)_publicationOutputServiceReference)?.Dispose(); - _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); - - _publicationOutputClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_publicationOutputClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _publicationOutputClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _publicationOutputClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _publicationOutputClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _publicationOutputServiceReference = _publicationOutputClient.ChannelFactory.CreateChannel(); - } - return _publicationOutputServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/OutputFormat.svc proxy - /// - /// The proxy - public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() - { -#if NET48 - if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_outputFormatServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_outputFormatClient)?.Dispose(); - ((IDisposable)_outputFormatServiceReference)?.Dispose(); - _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); - _outputFormatServiceReference = _outputFormatClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _outputFormatServiceReference; -#else - if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_outputFormatServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_outputFormatClient)?.Dispose(); - ((IDisposable)_outputFormatServiceReference)?.Dispose(); - _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); - - _outputFormatClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_outputFormatClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _outputFormatClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _outputFormatClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _outputFormatClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _outputFormatServiceReference = _outputFormatClient.ChannelFactory.CreateChannel(); - } - return _outputFormatServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/Settings.svc proxy - /// - /// The proxy - public Settings25ServiceReference.Settings GetSettings25Channel() - { -#if NET48 - if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_settingsServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_settingsClient)?.Dispose(); - ((IDisposable)_settingsServiceReference)?.Dispose(); - _settingsClient = new Settings25ServiceReference.SettingsClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Settings25])); - _settingsServiceReference = _settingsClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _settingsServiceReference; -#else - if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_settingsServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_settingsClient)?.Dispose(); - ((IDisposable)_settingsServiceReference)?.Dispose(); - _settingsClient = new Settings25ServiceReference.SettingsClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Settings25])); - - _settingsClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_settingsClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _settingsClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _settingsClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _settingsClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _settingsServiceReference = _settingsClient.ChannelFactory.CreateChannel(); - } - return _settingsServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/Edt.svc proxy - /// - /// The proxy - public EDT25ServiceReference.EDT GetEDT25Channel() - { -#if NET48 - if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_EDTServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_EDTClient)?.Dispose(); - ((IDisposable)_EDTServiceReference)?.Dispose(); - _EDTClient = new EDT25ServiceReference.EDTClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[EDT25])); - _EDTServiceReference = _EDTClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _EDTServiceReference; -#else - if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_EDTServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_EDTClient)?.Dispose(); - ((IDisposable)_EDTServiceReference)?.Dispose(); - _EDTClient = new EDT25ServiceReference.EDTClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[EDT25])); - - _EDTClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_EDTClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _EDTClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _EDTClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _EDTClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _EDTServiceReference = _EDTClient.ChannelFactory.CreateChannel(); - } - return _EDTServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/EventMonitor.svc proxy - /// - /// The proxy - public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() - { -#if NET48 - if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_eventMonitorServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_eventMonitorClient)?.Dispose(); - ((IDisposable)_eventMonitorServiceReference)?.Dispose(); - _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); - _eventMonitorServiceReference = _eventMonitorClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _eventMonitorServiceReference; -#else - if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_eventMonitorServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_eventMonitorClient)?.Dispose(); - ((IDisposable)_eventMonitorServiceReference)?.Dispose(); - _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); - - _eventMonitorClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_eventMonitorClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _eventMonitorClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _eventMonitorClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _eventMonitorClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _eventMonitorServiceReference = _eventMonitorClient.ChannelFactory.CreateChannel(); - } - return _eventMonitorServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/Baseline.svc proxy - /// - /// The proxy - public Baseline25ServiceReference.Baseline GetBaseline25Channel() - { -#if NET48 - if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_baselineServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_baselineClient)?.Dispose(); - ((IDisposable)_baselineServiceReference)?.Dispose(); - _baselineClient = new Baseline25ServiceReference.BaselineClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Baseline25])); - _baselineServiceReference = _baselineClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _baselineServiceReference; -#else - if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_baselineServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_baselineClient)?.Dispose(); - ((IDisposable)_baselineServiceReference)?.Dispose(); - _baselineClient = new Baseline25ServiceReference.BaselineClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Baseline25])); - - _baselineClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_baselineClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _baselineClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _baselineClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _baselineClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _baselineServiceReference = _baselineClient.ChannelFactory.CreateChannel(); - } - return _baselineServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/MetadataBinding.svc proxy - /// - /// The proxy - public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Channel() - { -#if NET48 - if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_metadataBindingServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_metadataBindingClient)?.Dispose(); - ((IDisposable)_metadataBindingServiceReference)?.Dispose(); - _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); - _metadataBindingServiceReference = _metadataBindingClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _metadataBindingServiceReference; -#else - if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_metadataBindingServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_metadataBindingClient)?.Dispose(); - ((IDisposable)_metadataBindingServiceReference)?.Dispose(); - _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); - - _metadataBindingClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_metadataBindingClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _metadataBindingClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _metadataBindingClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _metadataBindingClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _metadataBindingServiceReference = _metadataBindingClient.ChannelFactory.CreateChannel(); - } - return _metadataBindingServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/Search.svc proxy - /// - /// The proxy - public Search25ServiceReference.Search GetSearch25Channel() - { -#if NET48 - if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_searchServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_searchClient)?.Dispose(); - ((IDisposable)_searchServiceReference)?.Dispose(); - _searchClient = new Search25ServiceReference.SearchClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Search25])); - _searchServiceReference = _searchClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _searchServiceReference; -#else - if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_searchServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_searchClient)?.Dispose(); - ((IDisposable)_searchServiceReference)?.Dispose(); - _searchClient = new Search25ServiceReference.SearchClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[Search25])); - - _searchClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_searchClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _searchClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _searchClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _searchClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _searchServiceReference = _searchClient.ChannelFactory.CreateChannel(); - } - return _searchServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/TranslationJob.svc proxy - /// - /// The proxy - public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channel() - { -#if NET48 - if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_translationJobServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_translationJobClient)?.Dispose(); - ((IDisposable)_translationJobServiceReference)?.Dispose(); - _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); - _translationJobServiceReference = _translationJobClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _translationJobServiceReference; -#else - if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_translationJobServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_translationJobClient)?.Dispose(); - ((IDisposable)_translationJobServiceReference)?.Dispose(); - _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); - - _translationJobClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_translationJobClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _translationJobClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _translationJobClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _translationJobClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _translationJobServiceReference = _translationJobClient.ChannelFactory.CreateChannel(); - } - return _translationJobServiceReference; -#endif - } - - /// - /// Create a /Wcf/API25/TranslationTemplate.svc proxy - /// - /// The proxy - public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationTemplate25Channel() - { -#if NET48 - if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_translationTemplateServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_translationTemplateClient)?.Dispose(); - ((IDisposable)_translationTemplateServiceReference)?.Dispose(); - _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); - _translationTemplateServiceReference = _translationTemplateClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _translationTemplateServiceReference; -#else - if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_translationTemplateServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_translationTemplateClient)?.Dispose(); - ((IDisposable)_translationTemplateServiceReference)?.Dispose(); - _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); - - _translationTemplateClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_translationTemplateClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _translationTemplateClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _translationTemplateClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _translationTemplateClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _translationTemplateServiceReference = _translationTemplateClient.ChannelFactory.CreateChannel(); - } - return _translationTemplateServiceReference; -#endif - } - - - /// - /// Create a /Wcf/API25/BackgroundTask.svc proxy - /// - /// The proxy - public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channel() - { -#if NET48 - if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_backgroundTaskServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_backgroundTaskClient)?.Dispose(); - ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); - _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); - _backgroundTaskServiceReference = _backgroundTaskClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); - } - return _backgroundTaskServiceReference; -#else - if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || - (_backgroundTaskServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) - { - ((IDisposable)_backgroundTaskClient)?.Dispose(); - ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); - _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( - _commonBinding, - new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); - - _backgroundTaskClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_backgroundTaskClient.ChannelFactory.Credentials); - var bearerCredentials = GetBearerCredentials(); - _backgroundTaskClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); - - _backgroundTaskClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _backgroundTaskClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() - { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; - } - _backgroundTaskServiceReference = _backgroundTaskClient.ChannelFactory.CreateChannel(); - } - return _backgroundTaskServiceReference; -#endif - } - #endregion - - #region Private Methods - /// - /// One location to bind relative urls to service names - /// - private void ResolveServiceUris() - { - _serviceUriByServiceName.Add(Annotation25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Annotation.svc")); - _serviceUriByServiceName.Add(Application25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Application.svc")); - _serviceUriByServiceName.Add(DocumentObj25, new Uri(InfoShareWSBaseUri, "Wcf/API25/DocumentObj.svc")); - _serviceUriByServiceName.Add(Folder25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Folder.svc")); - _serviceUriByServiceName.Add(User25, new Uri(InfoShareWSBaseUri, "Wcf/API25/User.svc")); - _serviceUriByServiceName.Add(UserRole25, new Uri(InfoShareWSBaseUri, "Wcf/API25/UserRole.svc")); - _serviceUriByServiceName.Add(UserGroup25, new Uri(InfoShareWSBaseUri, "Wcf/API25/UserGroup.svc")); - _serviceUriByServiceName.Add(ListOfValues25, new Uri(InfoShareWSBaseUri, "Wcf/API25/ListOfValues.svc")); - _serviceUriByServiceName.Add(PublicationOutput25, new Uri(InfoShareWSBaseUri, "Wcf/API25/PublicationOutput.svc")); - _serviceUriByServiceName.Add(OutputFormat25, new Uri(InfoShareWSBaseUri, "Wcf/API25/OutputFormat.svc")); - _serviceUriByServiceName.Add(Settings25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Settings.svc")); - _serviceUriByServiceName.Add(EDT25, new Uri(InfoShareWSBaseUri, "Wcf/API25/EDT.svc")); - _serviceUriByServiceName.Add(EventMonitor25, new Uri(InfoShareWSBaseUri, "Wcf/API25/EventMonitor.svc")); - _serviceUriByServiceName.Add(Baseline25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Baseline.svc")); - _serviceUriByServiceName.Add(MetadataBinding25, new Uri(InfoShareWSBaseUri, "Wcf/API25/MetadataBinding.svc")); - _serviceUriByServiceName.Add(Search25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Search.svc")); - _serviceUriByServiceName.Add(TranslationJob25, new Uri(InfoShareWSBaseUri, "Wcf/API25/TranslationJob.svc")); - _serviceUriByServiceName.Add(TranslationTemplate25, new Uri(InfoShareWSBaseUri, "Wcf/API25/TranslationTemplate.svc")); - _serviceUriByServiceName.Add(BackgroundTask25, new Uri(InfoShareWSBaseUri, "Wcf/API25/BackgroundTask.svc")); - } - - /// - /// Returns the connection configuration (loaded from base [InfoShareWSBaseUri]/connectionconfiguration.xml) - /// - /// The connection configuration. - private XDocument LoadConnectionConfiguration() - { - HttpClientHandler handler = new HttpClientHandler(); - if (_connectionParameters.IgnoreSslPolicyErrors) - { - handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; - } - handler.SslProtocols = (System.Security.Authentication.SslProtocols)(SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13); - var httpClient = new HttpClient(handler); - httpClient.Timeout = _connectionParameters.Timeout; - var connectionConfigurationUri = new Uri(InfoShareWSBaseUri, "connectionconfiguration.xml"); - _logger.WriteDebug($"LoadConnectionConfiguration uri[{connectionConfigurationUri}] timeout[{httpClient.Timeout}]"); - var responseMessage = httpClient.GetAsync(connectionConfigurationUri).Result; - string response = responseMessage.Content.ReadAsStringAsync().Result; - - var connectionConfiguration = XDocument.Parse(response); - return connectionConfiguration; - } - -#if NET48 - /// - /// Wrapping the Bearer/Access Token as jwt (Json Web Token) claim into a Saml 2.0 token to push over WCF (Windows Communication Foundation) SOAP - /// Inspired by, hence hat tip to, - /// https://leastprivilege.com/2015/07/02/give-your-wcf-security-architecture-a-makeover-with-identityserver3/ - /// https://github.com/IdentityServer/IdentityServer3/issues/1107 - /// https://stackoverflow.com/questions/16312907/delivering-a-jwt-securitytoken-to-a-wcf-client - /// https://github.com/IdentityServer/IdentityServer3.Samples/tree/dev/source/Clients/WcfService - /// - private static GenericXmlSecurityToken WrapJwt(string jwt) - { - var subject = new ClaimsIdentity("saml"); - subject.AddClaim(new Claim("jwt", jwt)); - - var descriptor = new SecurityTokenDescriptor - { - TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0", - TokenIssuerName = "urn:wrappedjwt", - Subject = subject, - }; - - var handler = new System.IdentityModel.Tokens.Saml2SecurityTokenHandler(); - - var token = handler.CreateToken(descriptor); - var sb = new StringBuilder(128); - using (var xmlTextWriter = new XmlTextWriter(new StringWriter(sb))) - { - handler.WriteToken(xmlTextWriter, token); - var xmlDocument = new XmlDocument(); - xmlDocument.LoadXml(sb.ToString()); - var xmlToken = new GenericXmlSecurityToken( - xmlDocument.DocumentElement, - null, - DateTime.UtcNow, - DateTime.UtcNow.AddHours(1), - null, - null, - null); - return xmlToken; - } - } -#else - /// - /// NET6+ SOAP web services (/ISHWS/OWCF/) with OpenIdConnect authentication need a way to pass the Access/Bearer token. - /// This method wraps the token up in a SAML token which passes nicely over Windows Communication Foundation as Bearer Token on the Endpoint. - /// - private BearerCredentials GetBearerCredentials() - { - BearerCredentials bearerCredentials = new BearerCredentials(GetAccessToken().Value); - return bearerCredentials; - } -#endif - - #endregion - - #region IDisposable Methods - /// - /// Disposes the object - /// - public void Dispose() - { - ((IDisposable) _annotationClient)?.Dispose(); - ((IDisposable)_annotationServiceReference)?.Dispose(); - ((IDisposable)_annotationClient)?.Dispose(); - ((IDisposable)_annotationServiceReference)?.Dispose(); - ((IDisposable)_applicationClient)?.Dispose(); - ((IDisposable)_applicationServiceReference)?.Dispose(); - ((IDisposable)_applicationClient)?.Dispose(); - ((IDisposable)_applicationServiceReference)?.Dispose(); - ((IDisposable)_documentObjClient)?.Dispose(); - ((IDisposable)_documentObjServiceReference)?.Dispose(); - ((IDisposable)_documentObjClient)?.Dispose(); - ((IDisposable)_documentObjServiceReference)?.Dispose(); - ((IDisposable)_folderClient)?.Dispose(); - ((IDisposable)_folderServiceReference)?.Dispose(); - ((IDisposable)_folderClient)?.Dispose(); - ((IDisposable)_folderServiceReference)?.Dispose(); - ((IDisposable)_userClient)?.Dispose(); - ((IDisposable)_userServiceReference)?.Dispose(); - ((IDisposable)_userClient)?.Dispose(); - ((IDisposable)_userServiceReference)?.Dispose(); - ((IDisposable)_userRoleClient)?.Dispose(); - ((IDisposable)_userRoleServiceReference)?.Dispose(); - ((IDisposable)_userRoleClient)?.Dispose(); - ((IDisposable)_userRoleServiceReference)?.Dispose(); - ((IDisposable)_userGroupClient)?.Dispose(); - ((IDisposable)_userGroupServiceReference)?.Dispose(); - ((IDisposable)_userGroupClient)?.Dispose(); - ((IDisposable)_userGroupServiceReference)?.Dispose(); - ((IDisposable)_listOfValuesClient)?.Dispose(); - ((IDisposable)_listOfValuesServiceReference)?.Dispose(); - ((IDisposable)_listOfValuesClient)?.Dispose(); - ((IDisposable)_listOfValuesServiceReference)?.Dispose(); - ((IDisposable)_publicationOutputClient)?.Dispose(); - ((IDisposable)_publicationOutputServiceReference)?.Dispose(); - ((IDisposable)_publicationOutputClient)?.Dispose(); - ((IDisposable)_publicationOutputServiceReference)?.Dispose(); - ((IDisposable)_outputFormatClient)?.Dispose(); - ((IDisposable)_outputFormatServiceReference)?.Dispose(); - ((IDisposable)_outputFormatClient)?.Dispose(); - ((IDisposable)_outputFormatServiceReference)?.Dispose(); - ((IDisposable)_settingsClient)?.Dispose(); - ((IDisposable)_settingsServiceReference)?.Dispose(); - ((IDisposable)_settingsClient)?.Dispose(); - ((IDisposable)_settingsServiceReference)?.Dispose(); - ((IDisposable)_EDTClient)?.Dispose(); - ((IDisposable)_EDTServiceReference)?.Dispose(); - ((IDisposable)_EDTClient)?.Dispose(); - ((IDisposable)_EDTServiceReference)?.Dispose(); - ((IDisposable)_eventMonitorClient)?.Dispose(); - ((IDisposable)_eventMonitorServiceReference)?.Dispose(); - ((IDisposable)_eventMonitorClient)?.Dispose(); - ((IDisposable)_eventMonitorServiceReference)?.Dispose(); - ((IDisposable)_baselineClient)?.Dispose(); - ((IDisposable)_baselineServiceReference)?.Dispose(); - ((IDisposable)_baselineClient)?.Dispose(); - ((IDisposable)_baselineServiceReference)?.Dispose(); - ((IDisposable)_metadataBindingClient)?.Dispose(); - ((IDisposable)_metadataBindingServiceReference)?.Dispose(); - ((IDisposable)_metadataBindingClient)?.Dispose(); - ((IDisposable)_metadataBindingServiceReference)?.Dispose(); - ((IDisposable)_searchClient)?.Dispose(); - ((IDisposable)_searchServiceReference)?.Dispose(); - ((IDisposable)_searchClient)?.Dispose(); - ((IDisposable)_searchServiceReference)?.Dispose(); - ((IDisposable)_translationJobClient)?.Dispose(); - ((IDisposable)_translationJobServiceReference)?.Dispose(); - ((IDisposable)_translationJobClient)?.Dispose(); - ((IDisposable)_translationJobServiceReference)?.Dispose(); - ((IDisposable)_translationTemplateClient)?.Dispose(); - ((IDisposable)_translationTemplateServiceReference)?.Dispose(); - ((IDisposable)_translationTemplateClient)?.Dispose(); - ((IDisposable)_translationTemplateServiceReference)?.Dispose(); - ((IDisposable)_backgroundTaskClient)?.Dispose(); - ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); - ((IDisposable)_backgroundTaskClient)?.Dispose(); - ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); - } - /// - /// Disposes the object - /// - public void Close() - { - Dispose(); - } - #endregion - } -} +/* +* Copyright (c) 2014 All Rights Reserved by the SDL Group. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens; +using System.Net.Http; +using System.ServiceModel; +using System.Xml.Linq; +using Trisoft.ISHRemote.Interfaces; +using System.ServiceModel.Security; +using System.Security.Cryptography.X509Certificates; +using System.Net; +using System.Net.Http.Headers; +using System.Security.Claims; +using System.Text; +using System.Xml; +using System.IO; + +#if !NET48 +using System.ServiceModel.Federation; +#endif + +namespace Trisoft.ISHRemote.Connection +{ + /// + /// Dynamic proxy (so without app.config) generation of Service References towards the InfoShare Web Services writen in Windows Communication Foundation (WCF) protected by OpenIdConnect security protocol. + /// On ISHRemote v1 and earlier, so in turn before InfoShare 15 and earlier, this class was your starting point for dynamic proxy (so without app.config) generation of Service References. The inital class was written in .NET Framework style. Inspired by https://devblogs.microsoft.com/dotnet/wsfederationhttpbinding-in-net-standard-wcf/ this class has pragmas to illustrate .NET Framework and .NET 6.0+ style side-by-side. + /// + internal sealed class InfoShareWcfSoapWithOpenIdConnectConnection : InfoShareOpenIdConnectConnectionBase, IDisposable + { + #region Constants + /// + /// Annotation25 + /// + private const string Annotation25 = "Annotation25"; + /// + /// Application25 + /// + private const string Application25 = "Application25"; + /// + /// DocumentObj25 + /// + private const string DocumentObj25 = "DocumentObj25"; + /// + /// Folder25 + /// + private const string Folder25 = "Folder25"; + /// + /// User25 + /// + private const string User25 = "User25"; + /// + /// UserRole25 + /// + private const string UserRole25 = "UserRole25"; + /// + /// UserGroup25 + /// + private const string UserGroup25 = "UserGroup25"; + /// + /// ListOfValues25 + /// + private const string ListOfValues25 = "ListOfValues25"; + /// + /// PublicationOutput25 + /// + private const string PublicationOutput25 = "PublicationOutput25"; + /// + /// OutputFormat25 + /// + private const string OutputFormat25 = "OutputFormat25"; + /// + /// Settings25 + /// + private const string Settings25 = "Settings25"; + /// + /// EDT25 + /// + private const string EDT25 = "EDT25"; + /// + /// EventMonitor25 + /// + private const string EventMonitor25 = "EventMonitor25"; + /// + /// Baseline25 + /// + private const string Baseline25 = "Baseline25"; + /// + /// MetadataBinding25 + /// + private const string MetadataBinding25 = "MetadataBinding25"; + /// + /// Search25 + /// + private const string Search25 = "Search25"; + /// + /// TranslationJob25 + /// + private const string TranslationJob25 = "TranslationJob25"; + /// + /// TranslationTemplate25 + /// + private const string TranslationTemplate25 = "TranslationTemplate25"; + /// + /// BackgroundTask25 + /// + private const string BackgroundTask25 = "BackgroundTask25"; + #endregion + + #region Private Members + /// + /// Service URIs by service. + /// + private readonly Dictionary _serviceUriByServiceName = new Dictionary(); +#if NET48 + /// + /// Binding that is common for every endpoint. + /// + private readonly WS2007FederationHttpBinding _commonBinding; +#else + /// + /// Binding that is common for every endpoint. + /// + private readonly WSFederationHttpBinding _commonBinding; +#endif + + /// + /// Proxy for annotation + /// + private Annotation25ServiceReference.AnnotationClient _annotationClient; + private Annotation25ServiceReference.Annotation _annotationServiceReference; + /// + /// Proxy for application + /// + private Application25ServiceReference.ApplicationClient _applicationClient; + private Application25ServiceReference.Application _applicationServiceReference; + /// + /// Proxy for document obj + /// + private DocumentObj25ServiceReference.DocumentObjClient _documentObjClient; + private DocumentObj25ServiceReference.DocumentObj _documentObjServiceReference; + /// + /// Proxy for folder + /// + private Folder25ServiceReference.FolderClient _folderClient; + private Folder25ServiceReference.Folder _folderServiceReference; + /// + /// Proxy for user + /// + private User25ServiceReference.UserClient _userClient; + private User25ServiceReference.User _userServiceReference; + /// + /// Proxy for user role + /// + private UserRole25ServiceReference.UserRoleClient _userRoleClient; + private UserRole25ServiceReference.UserRole _userRoleServiceReference; + /// + /// Proxy for user group + /// + private UserGroup25ServiceReference.UserGroupClient _userGroupClient; + private UserGroup25ServiceReference.UserGroup _userGroupServiceReference; + /// + /// Proxy for LOV + /// + private ListOfValues25ServiceReference.ListOfValuesClient _listOfValuesClient; + private ListOfValues25ServiceReference.ListOfValues _listOfValuesServiceReference; + /// + /// Proxy for publication output + /// + private PublicationOutput25ServiceReference.PublicationOutputClient _publicationOutputClient; + private PublicationOutput25ServiceReference.PublicationOutput _publicationOutputServiceReference; + /// + /// Proxy for output format + /// + private OutputFormat25ServiceReference.OutputFormatClient _outputFormatClient; + private OutputFormat25ServiceReference.OutputFormat _outputFormatServiceReference; + /// + /// Proxy for settings + /// + private Settings25ServiceReference.SettingsClient _settingsClient; + private Settings25ServiceReference.Settings _settingsServiceReference; + /// + /// Proxy for EDT + /// + private EDT25ServiceReference.EDTClient _EDTClient; + private EDT25ServiceReference.EDT _EDTServiceReference; + /// + /// Proxy for event monitor + /// + private EventMonitor25ServiceReference.EventMonitorClient _eventMonitorClient; + private EventMonitor25ServiceReference.EventMonitor _eventMonitorServiceReference; + /// + /// Proxy for baseline + /// + private Baseline25ServiceReference.BaselineClient _baselineClient; + private Baseline25ServiceReference.Baseline _baselineServiceReference; + /// + /// Proxy for metadata binding + /// + private MetadataBinding25ServiceReference.MetadataBindingClient _metadataBindingClient; + private MetadataBinding25ServiceReference.MetadataBinding _metadataBindingServiceReference; + /// + /// Proxy for search + /// + private Search25ServiceReference.SearchClient _searchClient; + private Search25ServiceReference.Search _searchServiceReference; + /// + /// Proxy for translation job + /// + private TranslationJob25ServiceReference.TranslationJobClient _translationJobClient; + private TranslationJob25ServiceReference.TranslationJob _translationJobServiceReference; + /// + /// Proxy for translation template + /// + private TranslationTemplate25ServiceReference.TranslationTemplateClient _translationTemplateClient; + private TranslationTemplate25ServiceReference.TranslationTemplate _translationTemplateServiceReference; + /// + /// Proxy for background task + /// + private BackgroundTask25ServiceReference.BackgroundTaskClient _backgroundTaskClient; + private BackgroundTask25ServiceReference.BackgroundTask _backgroundTaskServiceReference; + #endregion Private Members + + #region Constructors + /// + /// Initializes a new instance of InfoShareWcfSoapWithOpenIdConnectConnection class. + /// + /// Instance of Interfaces.ILogger implementation + /// Incoming reused, probably Ssl/Tls initialized already. + /// OpenIdConnect connection parameters to be shared with WcfSoapWithOpenIdConnect and OpenApiWithOpenIdConnect + public InfoShareWcfSoapWithOpenIdConnectConnection(ILogger logger, HttpClient httpClient, InfoShareOpenIdConnectConnectionParameters infoShareOpenIdConnectConnectionParameters) + : base(logger, httpClient, infoShareOpenIdConnectConnectionParameters) + { + _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection InfoShareWSUrl[{_connectionParameters.InfoShareWSUrl}]"); + if (_connectionParameters.Tokens == null) + { + if ((string.IsNullOrEmpty(_connectionParameters.ClientId)) && (string.IsNullOrEmpty(_connectionParameters.ClientSecret))) + { + // attempt System Browser retrieval of Access/Bearer Token + _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection System Browser"); + _connectionParameters.Tokens = GetTokensOverSystemBrowserAsync().GetAwaiter().GetResult(); + } + else if ((!string.IsNullOrEmpty(_connectionParameters.ClientId)) && (!string.IsNullOrEmpty(_connectionParameters.ClientSecret))) + { + // Raw method without OidcClient, see GetTokensOverClientCredentialsRaw(); + _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection ClientId[{_connectionParameters.ClientId}] ClientSecret[{new string('*', _connectionParameters.ClientSecret.Length)}]"); + _connectionParameters.Tokens = GetTokensOverClientCredentialsAsync().GetAwaiter().GetResult(); + } + else + { + throw new ArgumentException("Expected ClientId and ClientSecret to be not null or empty."); + } + } + else + { + // Don't think this will happen + _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection reusing AccessToken[{_connectionParameters.Tokens.AccessToken}] AccessTokenExpiration[{_connectionParameters.Tokens.AccessTokenExpiration}]"); + } + _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection Access Token received ValidTo[{_connectionParameters.Tokens.AccessTokenExpiration.ToString("yyyyMMdd.HHmmss.fff")}]"); + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _connectionParameters.Tokens.AccessToken); + // using the ISHWS url from connectionconfiguration.xml instead of the potentially wrongly cased incoming one [TS-10630] + _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection using Normalized infoShareWSBaseUri[{_connectionParameters.InfoShareWSUrl}]"); + this.InfoShareWSBaseUri = _connectionParameters.InfoShareWSUrl; + + _logger.WriteDebug($"InfoShareWcfSoapWithOpenIdConnectConnection Resolving Service Uris"); + ResolveServiceUris(); + +#if NET48 + _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Resolving Binding (NET48)"); + _commonBinding = new WS2007FederationHttpBinding(WSFederationHttpSecurityMode.TransportWithMessageCredential); + _commonBinding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey; + _commonBinding.Security.Message.IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0"; +#else + _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Resolving Binding (NET6+)"); + _commonBinding = new WSFederationHttpBinding(new WSTrustTokenParameters + { + TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0", + KeyType = SecurityKeyType.BearerKey + }); +#endif + _commonBinding.Security.Message.EstablishSecurityContext = false; + _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Binding Text ReaderQuotas"); + _commonBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; + _commonBinding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue; + _commonBinding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; + _commonBinding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue; + _commonBinding.ReaderQuotas.MaxDepth = 64; + _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Binding Transport Quotas"); + _commonBinding.MaxReceivedMessageSize = Int32.MaxValue; + _commonBinding.MaxBufferPoolSize = Int32.MaxValue; + _logger.WriteDebug("InfoShareWcfSoapWithOpenIdConnectConnection Binding Send/Receive Timeouts"); + _commonBinding.SendTimeout = _connectionParameters.IssueTimeout; + _commonBinding.ReceiveTimeout = _connectionParameters.IssueTimeout; + } + #endregion + + #region Public Properties + /// + /// Root uri for the Web Services + /// + public Uri InfoShareWSBaseUri { get; private set; } + #endregion Public Properties + + #region Private Faulted Event Handlers + /// + /// Event handler for when the Annotation client channel enters a Faulted state + /// + private void AnnotationClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"AnnotationClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _annotationClient = null; + _annotationServiceReference = null; + } + + /// + /// Event handler for when the Application client channel enters a Faulted state + /// + private void ApplicationClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"ApplicationClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _applicationClient = null; + _applicationServiceReference = null; + } + + /// + /// Event handler for when the DocumentObj client channel enters a Faulted state + /// + private void DocumentObjClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"DocumentObjClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _documentObjClient = null; + _documentObjServiceReference = null; + } + + /// + /// Event handler for when the Folder client channel enters a Faulted state + /// + private void FolderClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"FolderClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _folderClient = null; + _folderServiceReference = null; + } + + /// + /// Event handler for when the User client channel enters a Faulted state + /// + private void UserClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"UserClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _userClient = null; + _userServiceReference = null; + } + + /// + /// Event handler for when the UserRole client channel enters a Faulted state + /// + private void UserRoleClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"UserRoleClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _userRoleClient = null; + _userRoleServiceReference = null; + } + + /// + /// Event handler for when the UserGroup client channel enters a Faulted state + /// + private void UserGroupClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"UserGroupClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _userGroupClient = null; + _userGroupServiceReference = null; + } + + /// + /// Event handler for when the ListOfValues client channel enters a Faulted state + /// + private void ListOfValuesClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"ListOfValuesClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _listOfValuesClient = null; + _listOfValuesServiceReference = null; + } + + /// + /// Event handler for when the PublicationOutput client channel enters a Faulted state + /// + private void PublicationOutputClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"PublicationOutputClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _publicationOutputClient = null; + _publicationOutputServiceReference = null; + } + + /// + /// Event handler for when the OutputFormat client channel enters a Faulted state + /// + private void OutputFormatClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"OutputFormatClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _outputFormatClient = null; + _outputFormatServiceReference = null; + } + + /// + /// Event handler for when the Settings client channel enters a Faulted state + /// + private void SettingsClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"SettingsClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _settingsClient = null; + _settingsServiceReference = null; + } + + /// + /// Event handler for when the EDT client channel enters a Faulted state + /// + private void EDTClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"EDTClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _EDTClient = null; + _EDTServiceReference = null; + } + + /// + /// Event handler for when the EventMonitor client channel enters a Faulted state + /// + private void EventMonitorClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"EventMonitorClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _eventMonitorClient = null; + _eventMonitorServiceReference = null; + } + + /// + /// Event handler for when the Baseline client channel enters a Faulted state + /// + private void BaselineClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"BaselineClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _baselineClient = null; + _baselineServiceReference = null; + } + + /// + /// Event handler for when the MetadataBinding client channel enters a Faulted state + /// + private void MetadataBindingClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"MetadataBindingClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _metadataBindingClient = null; + _metadataBindingServiceReference = null; + } + + /// + /// Event handler for when the Search client channel enters a Faulted state + /// + private void SearchClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"SearchClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _searchClient = null; + _searchServiceReference = null; + } + + /// + /// Event handler for when the TranslationJob client channel enters a Faulted state + /// + private void TranslationJobClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"TranslationJobClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _translationJobClient = null; + _translationJobServiceReference = null; + } + + /// + /// Event handler for when the TranslationTemplate client channel enters a Faulted state + /// + private void TranslationTemplateClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"TranslationTemplateClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _translationTemplateClient = null; + _translationTemplateServiceReference = null; + } + + /// + /// Event handler for when the BackgroundTask client channel enters a Faulted state + /// + private void BackgroundTaskClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"BackgroundTaskClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _backgroundTaskClient = null; + _backgroundTaskServiceReference = null; + } + #endregion Private Faulted Event Handlers + + #region Public Get..Channel Methods + /// + /// Create a /Wcf/API25/Annotation.svc proxy + /// + /// The proxy + public Annotation25ServiceReference.Annotation GetAnnotation25Channel() + { +#if NET48 + if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_annotationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}] ServiceRef[{(_annotationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_annotationClient)?.Dispose(); + ((IDisposable)_annotationServiceReference)?.Dispose(); + _annotationClient = new Annotation25ServiceReference.AnnotationClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Annotation25])); + ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); + _annotationServiceReference = _annotationClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _annotationServiceReference; +#else + if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_annotationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}] ServiceRef[{(_annotationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_annotationClient)?.Dispose(); + ((IDisposable)_annotationServiceReference)?.Dispose(); + _annotationClient = new Annotation25ServiceReference.AnnotationClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Annotation25])); + + ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); + + _annotationClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_annotationClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _annotationClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _annotationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _annotationClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _annotationServiceReference = _annotationClient.ChannelFactory.CreateChannel(); + } + return _annotationServiceReference; +#endif + } + /// + /// Create a /Wcf/API25/Application.svc proxy + /// + /// The proxy + public Application25ServiceReference.Application GetApplication25Channel() + { +#if NET48 + if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_applicationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}] ServiceRef[{(_applicationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_applicationClient)?.Dispose(); + ((IDisposable)_applicationServiceReference)?.Dispose(); + _applicationClient = new Application25ServiceReference.ApplicationClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Application25])); + ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); + _applicationServiceReference = _applicationClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _applicationServiceReference; +#else + if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_applicationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}] ServiceRef[{(_applicationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_applicationClient)?.Dispose(); + ((IDisposable)_applicationServiceReference)?.Dispose(); + _applicationClient = new Application25ServiceReference.ApplicationClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Application25])); + + ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); + + _applicationClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_applicationClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _applicationClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _applicationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _applicationClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _applicationServiceReference = _applicationClient.ChannelFactory.CreateChannel(); + } + return _applicationServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/DocumentObj.svc proxy + /// + /// The proxy + public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() + { +#if NET48 + if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_documentObjServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}] ServiceRef[{(_documentObjServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_documentObjClient)?.Dispose(); + ((IDisposable)_documentObjServiceReference)?.Dispose(); + _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); + ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); + _documentObjServiceReference = _documentObjClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _documentObjServiceReference; +#else + if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_documentObjServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}] ServiceRef[{(_documentObjServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_documentObjClient)?.Dispose(); + ((IDisposable)_documentObjServiceReference)?.Dispose(); + _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); + ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); + + _documentObjClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_documentObjClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _documentObjClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _documentObjClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _documentObjClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _documentObjServiceReference = _documentObjClient.ChannelFactory.CreateChannel(); + } + return _documentObjServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/Folder.svc proxy + /// + /// The proxy + public Folder25ServiceReference.Folder GetFolder25Channel() + { +#if NET48 + if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_folderServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}] ServiceRef[{(_folderServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_folderClient)?.Dispose(); + ((IDisposable)_folderServiceReference)?.Dispose(); + _folderClient = new Folder25ServiceReference.FolderClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Folder25])); + ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); + _folderServiceReference = _folderClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _folderServiceReference; +#else + if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_folderServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}] ServiceRef[{(_folderServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_folderClient)?.Dispose(); + ((IDisposable)_folderServiceReference)?.Dispose(); + _folderClient = new Folder25ServiceReference.FolderClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Folder25])); + ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); + + _folderClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_folderClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _folderClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _folderClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _folderClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _folderServiceReference = _folderClient.ChannelFactory.CreateChannel(); + } + return _folderServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/User.svc proxy + /// + /// The proxy + public User25ServiceReference.User GetUser25Channel() + { +#if NET48 + if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_userServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}] ServiceRef[{(_userServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_userClient)?.Dispose(); + ((IDisposable)_userServiceReference)?.Dispose(); + _userClient = new User25ServiceReference.UserClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[User25])); + ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); + _userServiceReference = _userClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _userServiceReference; +#else + if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_userServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}] ServiceRef[{(_userServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_userClient)?.Dispose(); + ((IDisposable)_userServiceReference)?.Dispose(); + _userClient = new User25ServiceReference.UserClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[User25])); + ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); + + _userClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _userClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _userClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _userClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _userServiceReference = _userClient.ChannelFactory.CreateChannel(); + } + return _userServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/UserRole.svc proxy + /// + /// The proxy + public UserRole25ServiceReference.UserRole GetUserRole25Channel() + { +#if NET48 + if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_userRoleServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}] ServiceRef[{(_userRoleServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_userRoleClient)?.Dispose(); + ((IDisposable)_userRoleServiceReference)?.Dispose(); + _userRoleClient = new UserRole25ServiceReference.UserRoleClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[UserRole25])); + ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); + _userRoleServiceReference = _userRoleClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _userRoleServiceReference; +#else + if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_userRoleServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}] ServiceRef[{(_userRoleServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_userRoleClient)?.Dispose(); + ((IDisposable)_userRoleServiceReference)?.Dispose(); + _userRoleClient = new UserRole25ServiceReference.UserRoleClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[UserRole25])); + ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); + + _userRoleClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userRoleClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _userRoleClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _userRoleClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _userRoleClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _userRoleServiceReference = _userRoleClient.ChannelFactory.CreateChannel(); + } + return _userRoleServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/UserGroup.svc proxy + /// + /// The proxy + public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() + { +#if NET48 + if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_userGroupServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}] ServiceRef[{(_userGroupServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_userGroupClient)?.Dispose(); + ((IDisposable)_userGroupServiceReference)?.Dispose(); + _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[UserGroup25])); + ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); + _userGroupServiceReference = _userGroupClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _userGroupServiceReference; +#else + if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_userGroupServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}] ServiceRef[{(_userGroupServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_userGroupClient)?.Dispose(); + ((IDisposable)_userGroupServiceReference)?.Dispose(); + _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[UserGroup25])); + ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); + + _userGroupClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userGroupClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _userGroupClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _userGroupClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _userGroupClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _userGroupServiceReference = _userGroupClient.ChannelFactory.CreateChannel(); + } + return _userGroupServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/ListOfValues.svc proxy + /// + /// The proxy + public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() + { +#if NET48 + if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_listOfValuesServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}] ServiceRef[{(_listOfValuesServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_listOfValuesClient)?.Dispose(); + ((IDisposable)_listOfValuesServiceReference)?.Dispose(); + _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); + ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); + _listOfValuesServiceReference = _listOfValuesClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _listOfValuesServiceReference; +#else + if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_listOfValuesServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}] ServiceRef[{(_listOfValuesServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_listOfValuesClient)?.Dispose(); + ((IDisposable)_listOfValuesServiceReference)?.Dispose(); + _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); + ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); + + _listOfValuesClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_listOfValuesClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _listOfValuesClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _listOfValuesClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _listOfValuesClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _listOfValuesServiceReference = _listOfValuesClient.ChannelFactory.CreateChannel(); + } + return _listOfValuesServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/PublicationOutput.svc proxy + /// + /// The proxy + public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutput25Channel() + { +#if NET48 + if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_publicationOutputServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}] ServiceRef[{(_publicationOutputServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_publicationOutputClient)?.Dispose(); + ((IDisposable)_publicationOutputServiceReference)?.Dispose(); + _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); + ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); + _publicationOutputServiceReference = _publicationOutputClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _publicationOutputServiceReference; +#else + if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_publicationOutputServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}] ServiceRef[{(_publicationOutputServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_publicationOutputClient)?.Dispose(); + ((IDisposable)_publicationOutputServiceReference)?.Dispose(); + _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); + ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); + + _publicationOutputClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_publicationOutputClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _publicationOutputClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _publicationOutputClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _publicationOutputClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _publicationOutputServiceReference = _publicationOutputClient.ChannelFactory.CreateChannel(); + } + return _publicationOutputServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/OutputFormat.svc proxy + /// + /// The proxy + public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() + { +#if NET48 + if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_outputFormatServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}] ServiceRef[{(_outputFormatServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_outputFormatClient)?.Dispose(); + ((IDisposable)_outputFormatServiceReference)?.Dispose(); + _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); + ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); + _outputFormatServiceReference = _outputFormatClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _outputFormatServiceReference; +#else + if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_outputFormatServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}] ServiceRef[{(_outputFormatServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_outputFormatClient)?.Dispose(); + ((IDisposable)_outputFormatServiceReference)?.Dispose(); + _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); + ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); + + _outputFormatClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_outputFormatClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _outputFormatClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _outputFormatClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _outputFormatClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _outputFormatServiceReference = _outputFormatClient.ChannelFactory.CreateChannel(); + } + return _outputFormatServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/Settings.svc proxy + /// + /// The proxy + public Settings25ServiceReference.Settings GetSettings25Channel() + { +#if NET48 + if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_settingsServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}] ServiceRef[{(_settingsServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_settingsClient)?.Dispose(); + ((IDisposable)_settingsServiceReference)?.Dispose(); + _settingsClient = new Settings25ServiceReference.SettingsClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Settings25])); + ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); + _settingsServiceReference = _settingsClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _settingsServiceReference; +#else + if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_settingsServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}] ServiceRef[{(_settingsServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_settingsClient)?.Dispose(); + ((IDisposable)_settingsServiceReference)?.Dispose(); + _settingsClient = new Settings25ServiceReference.SettingsClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Settings25])); + ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); + + _settingsClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_settingsClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _settingsClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _settingsClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _settingsClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _settingsServiceReference = _settingsClient.ChannelFactory.CreateChannel(); + } + return _settingsServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/Edt.svc proxy + /// + /// The proxy + public EDT25ServiceReference.EDT GetEDT25Channel() + { +#if NET48 + if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_EDTServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}] ServiceRef[{(_EDTServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_EDTClient)?.Dispose(); + ((IDisposable)_EDTServiceReference)?.Dispose(); + _EDTClient = new EDT25ServiceReference.EDTClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[EDT25])); + ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); + _EDTServiceReference = _EDTClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _EDTServiceReference; +#else + if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_EDTServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}] ServiceRef[{(_EDTServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_EDTClient)?.Dispose(); + ((IDisposable)_EDTServiceReference)?.Dispose(); + _EDTClient = new EDT25ServiceReference.EDTClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[EDT25])); + ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); + + _EDTClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_EDTClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _EDTClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _EDTClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _EDTClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _EDTServiceReference = _EDTClient.ChannelFactory.CreateChannel(); + } + return _EDTServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/EventMonitor.svc proxy + /// + /// The proxy + public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() + { +#if NET48 + if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_eventMonitorServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}] ServiceRef[{(_eventMonitorServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_eventMonitorClient)?.Dispose(); + ((IDisposable)_eventMonitorServiceReference)?.Dispose(); + _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); + ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); + _eventMonitorServiceReference = _eventMonitorClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _eventMonitorServiceReference; +#else + if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_eventMonitorServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}] ServiceRef[{(_eventMonitorServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_eventMonitorClient)?.Dispose(); + ((IDisposable)_eventMonitorServiceReference)?.Dispose(); + _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); + ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); + + _eventMonitorClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_eventMonitorClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _eventMonitorClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _eventMonitorClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _eventMonitorClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _eventMonitorServiceReference = _eventMonitorClient.ChannelFactory.CreateChannel(); + } + return _eventMonitorServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/Baseline.svc proxy + /// + /// The proxy + public Baseline25ServiceReference.Baseline GetBaseline25Channel() + { +#if NET48 + if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_baselineServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}] ServiceRef[{(_baselineServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_baselineClient)?.Dispose(); + ((IDisposable)_baselineServiceReference)?.Dispose(); + _baselineClient = new Baseline25ServiceReference.BaselineClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Baseline25])); + ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); + _baselineServiceReference = _baselineClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _baselineServiceReference; +#else + if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_baselineServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}] ServiceRef[{(_baselineServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_baselineClient)?.Dispose(); + ((IDisposable)_baselineServiceReference)?.Dispose(); + _baselineClient = new Baseline25ServiceReference.BaselineClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Baseline25])); + ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); + + _baselineClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_baselineClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _baselineClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _baselineClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _baselineClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _baselineServiceReference = _baselineClient.ChannelFactory.CreateChannel(); + } + return _baselineServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/MetadataBinding.svc proxy + /// + /// The proxy + public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Channel() + { +#if NET48 + if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_metadataBindingServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}] ServiceRef[{(_metadataBindingServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_metadataBindingClient)?.Dispose(); + ((IDisposable)_metadataBindingServiceReference)?.Dispose(); + _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); + ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); + _metadataBindingServiceReference = _metadataBindingClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _metadataBindingServiceReference; +#else + if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_metadataBindingServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}] ServiceRef[{(_metadataBindingServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_metadataBindingClient)?.Dispose(); + ((IDisposable)_metadataBindingServiceReference)?.Dispose(); + _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); + ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); + + _metadataBindingClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_metadataBindingClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _metadataBindingClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _metadataBindingClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _metadataBindingClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _metadataBindingServiceReference = _metadataBindingClient.ChannelFactory.CreateChannel(); + } + return _metadataBindingServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/Search.svc proxy + /// + /// The proxy + public Search25ServiceReference.Search GetSearch25Channel() + { +#if NET48 + if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_searchServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}] ServiceRef[{(_searchServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_searchClient)?.Dispose(); + ((IDisposable)_searchServiceReference)?.Dispose(); + _searchClient = new Search25ServiceReference.SearchClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Search25])); + ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); + _searchServiceReference = _searchClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _searchServiceReference; +#else + if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_searchServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}] ServiceRef[{(_searchServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_searchClient)?.Dispose(); + ((IDisposable)_searchServiceReference)?.Dispose(); + _searchClient = new Search25ServiceReference.SearchClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[Search25])); + ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); + + _searchClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_searchClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _searchClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _searchClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _searchClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _searchServiceReference = _searchClient.ChannelFactory.CreateChannel(); + } + return _searchServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/TranslationJob.svc proxy + /// + /// The proxy + public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channel() + { +#if NET48 + if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_translationJobServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}] ServiceRef[{(_translationJobServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_translationJobClient)?.Dispose(); + ((IDisposable)_translationJobServiceReference)?.Dispose(); + _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); + ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); + _translationJobServiceReference = _translationJobClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _translationJobServiceReference; +#else + if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_translationJobServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}] ServiceRef[{(_translationJobServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_translationJobClient)?.Dispose(); + ((IDisposable)_translationJobServiceReference)?.Dispose(); + _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); + ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); + + _translationJobClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_translationJobClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _translationJobClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _translationJobClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _translationJobClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _translationJobServiceReference = _translationJobClient.ChannelFactory.CreateChannel(); + } + return _translationJobServiceReference; +#endif + } + + /// + /// Create a /Wcf/API25/TranslationTemplate.svc proxy + /// + /// The proxy + public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationTemplate25Channel() + { +#if NET48 + if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_translationTemplateServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}] ServiceRef[{(_translationTemplateServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_translationTemplateClient)?.Dispose(); + ((IDisposable)_translationTemplateServiceReference)?.Dispose(); + _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); + ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); + _translationTemplateServiceReference = _translationTemplateClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _translationTemplateServiceReference; +#else + if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_translationTemplateServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}] ServiceRef[{(_translationTemplateServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_translationTemplateClient)?.Dispose(); + ((IDisposable)_translationTemplateServiceReference)?.Dispose(); + _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); + ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); + + _translationTemplateClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_translationTemplateClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _translationTemplateClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _translationTemplateClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _translationTemplateClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _translationTemplateServiceReference = _translationTemplateClient.ChannelFactory.CreateChannel(); + } + return _translationTemplateServiceReference; +#endif + } + + + /// + /// Create a /Wcf/API25/BackgroundTask.svc proxy + /// + /// The proxy + public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channel() + { +#if NET48 + if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_backgroundTaskServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}] ServiceRef[{(_backgroundTaskServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_backgroundTaskClient)?.Dispose(); + ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); + _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); + ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); + _backgroundTaskServiceReference = _backgroundTaskClient.ChannelFactory.CreateChannelWithIssuedToken(WrapJwt(GetAccessToken().Value)); + } + return _backgroundTaskServiceReference; +#else + if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || + (_backgroundTaskServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) + { + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}] ServiceRef[{(_backgroundTaskServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + ((IDisposable)_backgroundTaskClient)?.Dispose(); + ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); + _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( + _commonBinding, + new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); + ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); + + _backgroundTaskClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_backgroundTaskClient.ChannelFactory.Credentials); + var bearerCredentials = GetBearerCredentials(); + _backgroundTaskClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); + + _backgroundTaskClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) + { + _backgroundTaskClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + _backgroundTaskServiceReference = _backgroundTaskClient.ChannelFactory.CreateChannel(); + } + return _backgroundTaskServiceReference; +#endif + } + #endregion + + #region Private Methods + /// + /// One location to bind relative urls to service names + /// + private void ResolveServiceUris() + { + _serviceUriByServiceName.Add(Annotation25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Annotation.svc")); + _serviceUriByServiceName.Add(Application25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Application.svc")); + _serviceUriByServiceName.Add(DocumentObj25, new Uri(InfoShareWSBaseUri, "Wcf/API25/DocumentObj.svc")); + _serviceUriByServiceName.Add(Folder25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Folder.svc")); + _serviceUriByServiceName.Add(User25, new Uri(InfoShareWSBaseUri, "Wcf/API25/User.svc")); + _serviceUriByServiceName.Add(UserRole25, new Uri(InfoShareWSBaseUri, "Wcf/API25/UserRole.svc")); + _serviceUriByServiceName.Add(UserGroup25, new Uri(InfoShareWSBaseUri, "Wcf/API25/UserGroup.svc")); + _serviceUriByServiceName.Add(ListOfValues25, new Uri(InfoShareWSBaseUri, "Wcf/API25/ListOfValues.svc")); + _serviceUriByServiceName.Add(PublicationOutput25, new Uri(InfoShareWSBaseUri, "Wcf/API25/PublicationOutput.svc")); + _serviceUriByServiceName.Add(OutputFormat25, new Uri(InfoShareWSBaseUri, "Wcf/API25/OutputFormat.svc")); + _serviceUriByServiceName.Add(Settings25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Settings.svc")); + _serviceUriByServiceName.Add(EDT25, new Uri(InfoShareWSBaseUri, "Wcf/API25/EDT.svc")); + _serviceUriByServiceName.Add(EventMonitor25, new Uri(InfoShareWSBaseUri, "Wcf/API25/EventMonitor.svc")); + _serviceUriByServiceName.Add(Baseline25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Baseline.svc")); + _serviceUriByServiceName.Add(MetadataBinding25, new Uri(InfoShareWSBaseUri, "Wcf/API25/MetadataBinding.svc")); + _serviceUriByServiceName.Add(Search25, new Uri(InfoShareWSBaseUri, "Wcf/API25/Search.svc")); + _serviceUriByServiceName.Add(TranslationJob25, new Uri(InfoShareWSBaseUri, "Wcf/API25/TranslationJob.svc")); + _serviceUriByServiceName.Add(TranslationTemplate25, new Uri(InfoShareWSBaseUri, "Wcf/API25/TranslationTemplate.svc")); + _serviceUriByServiceName.Add(BackgroundTask25, new Uri(InfoShareWSBaseUri, "Wcf/API25/BackgroundTask.svc")); + } + + /// + /// Returns the connection configuration (loaded from base [InfoShareWSBaseUri]/connectionconfiguration.xml) + /// + /// The connection configuration. + private XDocument LoadConnectionConfiguration() + { + HttpClientHandler handler = new HttpClientHandler(); + if (_connectionParameters.IgnoreSslPolicyErrors) + { + handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; + } + handler.SslProtocols = (System.Security.Authentication.SslProtocols)(SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13); + var httpClient = new HttpClient(handler); + httpClient.Timeout = _connectionParameters.Timeout; + var connectionConfigurationUri = new Uri(InfoShareWSBaseUri, "connectionconfiguration.xml"); + _logger.WriteDebug($"LoadConnectionConfiguration uri[{connectionConfigurationUri}] timeout[{httpClient.Timeout}]"); + var responseMessage = httpClient.GetAsync(connectionConfigurationUri).Result; + string response = responseMessage.Content.ReadAsStringAsync().Result; + + var connectionConfiguration = XDocument.Parse(response); + return connectionConfiguration; + } + +#if NET48 + /// + /// Wrapping the Bearer/Access Token as jwt (Json Web Token) claim into a Saml 2.0 token to push over WCF (Windows Communication Foundation) SOAP + /// Inspired by, hence hat tip to, + /// https://leastprivilege.com/2015/07/02/give-your-wcf-security-architecture-a-makeover-with-identityserver3/ + /// https://github.com/IdentityServer/IdentityServer3/issues/1107 + /// https://stackoverflow.com/questions/16312907/delivering-a-jwt-securitytoken-to-a-wcf-client + /// https://github.com/IdentityServer/IdentityServer3.Samples/tree/dev/source/Clients/WcfService + /// + private static GenericXmlSecurityToken WrapJwt(string jwt) + { + var subject = new ClaimsIdentity("saml"); + subject.AddClaim(new Claim("jwt", jwt)); + + var descriptor = new SecurityTokenDescriptor + { + TokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0", + TokenIssuerName = "urn:wrappedjwt", + Subject = subject, + }; + + var handler = new System.IdentityModel.Tokens.Saml2SecurityTokenHandler(); + + var token = handler.CreateToken(descriptor); + var sb = new StringBuilder(128); + using (var xmlTextWriter = new XmlTextWriter(new StringWriter(sb))) + { + handler.WriteToken(xmlTextWriter, token); + var xmlDocument = new XmlDocument(); + xmlDocument.LoadXml(sb.ToString()); + var xmlToken = new GenericXmlSecurityToken( + xmlDocument.DocumentElement, + null, + DateTime.UtcNow, + DateTime.UtcNow.AddHours(1), + null, + null, + null); + return xmlToken; + } + } +#else + /// + /// NET6+ SOAP web services (/ISHWS/OWCF/) with OpenIdConnect authentication need a way to pass the Access/Bearer token. + /// This method wraps the token up in a SAML token which passes nicely over Windows Communication Foundation as Bearer Token on the Endpoint. + /// + private BearerCredentials GetBearerCredentials() + { + BearerCredentials bearerCredentials = new BearerCredentials(GetAccessToken().Value); + return bearerCredentials; + } +#endif + + #endregion + + #region IDisposable Methods + /// + /// Disposes the object + /// + public void Dispose() + { + ((IDisposable) _annotationClient)?.Dispose(); + ((IDisposable)_annotationServiceReference)?.Dispose(); + ((IDisposable)_annotationClient)?.Dispose(); + ((IDisposable)_annotationServiceReference)?.Dispose(); + ((IDisposable)_applicationClient)?.Dispose(); + ((IDisposable)_applicationServiceReference)?.Dispose(); + ((IDisposable)_applicationClient)?.Dispose(); + ((IDisposable)_applicationServiceReference)?.Dispose(); + ((IDisposable)_documentObjClient)?.Dispose(); + ((IDisposable)_documentObjServiceReference)?.Dispose(); + ((IDisposable)_documentObjClient)?.Dispose(); + ((IDisposable)_documentObjServiceReference)?.Dispose(); + ((IDisposable)_folderClient)?.Dispose(); + ((IDisposable)_folderServiceReference)?.Dispose(); + ((IDisposable)_folderClient)?.Dispose(); + ((IDisposable)_folderServiceReference)?.Dispose(); + ((IDisposable)_userClient)?.Dispose(); + ((IDisposable)_userServiceReference)?.Dispose(); + ((IDisposable)_userClient)?.Dispose(); + ((IDisposable)_userServiceReference)?.Dispose(); + ((IDisposable)_userRoleClient)?.Dispose(); + ((IDisposable)_userRoleServiceReference)?.Dispose(); + ((IDisposable)_userRoleClient)?.Dispose(); + ((IDisposable)_userRoleServiceReference)?.Dispose(); + ((IDisposable)_userGroupClient)?.Dispose(); + ((IDisposable)_userGroupServiceReference)?.Dispose(); + ((IDisposable)_userGroupClient)?.Dispose(); + ((IDisposable)_userGroupServiceReference)?.Dispose(); + ((IDisposable)_listOfValuesClient)?.Dispose(); + ((IDisposable)_listOfValuesServiceReference)?.Dispose(); + ((IDisposable)_listOfValuesClient)?.Dispose(); + ((IDisposable)_listOfValuesServiceReference)?.Dispose(); + ((IDisposable)_publicationOutputClient)?.Dispose(); + ((IDisposable)_publicationOutputServiceReference)?.Dispose(); + ((IDisposable)_publicationOutputClient)?.Dispose(); + ((IDisposable)_publicationOutputServiceReference)?.Dispose(); + ((IDisposable)_outputFormatClient)?.Dispose(); + ((IDisposable)_outputFormatServiceReference)?.Dispose(); + ((IDisposable)_outputFormatClient)?.Dispose(); + ((IDisposable)_outputFormatServiceReference)?.Dispose(); + ((IDisposable)_settingsClient)?.Dispose(); + ((IDisposable)_settingsServiceReference)?.Dispose(); + ((IDisposable)_settingsClient)?.Dispose(); + ((IDisposable)_settingsServiceReference)?.Dispose(); + ((IDisposable)_EDTClient)?.Dispose(); + ((IDisposable)_EDTServiceReference)?.Dispose(); + ((IDisposable)_EDTClient)?.Dispose(); + ((IDisposable)_EDTServiceReference)?.Dispose(); + ((IDisposable)_eventMonitorClient)?.Dispose(); + ((IDisposable)_eventMonitorServiceReference)?.Dispose(); + ((IDisposable)_eventMonitorClient)?.Dispose(); + ((IDisposable)_eventMonitorServiceReference)?.Dispose(); + ((IDisposable)_baselineClient)?.Dispose(); + ((IDisposable)_baselineServiceReference)?.Dispose(); + ((IDisposable)_baselineClient)?.Dispose(); + ((IDisposable)_baselineServiceReference)?.Dispose(); + ((IDisposable)_metadataBindingClient)?.Dispose(); + ((IDisposable)_metadataBindingServiceReference)?.Dispose(); + ((IDisposable)_metadataBindingClient)?.Dispose(); + ((IDisposable)_metadataBindingServiceReference)?.Dispose(); + ((IDisposable)_searchClient)?.Dispose(); + ((IDisposable)_searchServiceReference)?.Dispose(); + ((IDisposable)_searchClient)?.Dispose(); + ((IDisposable)_searchServiceReference)?.Dispose(); + ((IDisposable)_translationJobClient)?.Dispose(); + ((IDisposable)_translationJobServiceReference)?.Dispose(); + ((IDisposable)_translationJobClient)?.Dispose(); + ((IDisposable)_translationJobServiceReference)?.Dispose(); + ((IDisposable)_translationTemplateClient)?.Dispose(); + ((IDisposable)_translationTemplateServiceReference)?.Dispose(); + ((IDisposable)_translationTemplateClient)?.Dispose(); + ((IDisposable)_translationTemplateServiceReference)?.Dispose(); + ((IDisposable)_backgroundTaskClient)?.Dispose(); + ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); + ((IDisposable)_backgroundTaskClient)?.Dispose(); + ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); + } + /// + /// Disposes the object + /// + public void Close() + { + Dispose(); + } + #endregion + } +} diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs index eebab26e..7f4e55b0 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs @@ -340,6 +340,198 @@ public bool IsTokenAlmostExpired } #endregion Properties + #region Private Faulted Event Handlers + /// + /// Event handler for when the Annotation client channel enters a Faulted state + /// + private void AnnotationClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"AnnotationClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _annotationClient = null; + } + + /// + /// Event handler for when the Application client channel enters a Faulted state + /// + private void ApplicationClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"ApplicationClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _applicationClient = null; + } + + /// + /// Event handler for when the DocumentObj client channel enters a Faulted state + /// + private void DocumentObjClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"DocumentObjClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _documentObjClient = null; + } + + /// + /// Event handler for when the Folder client channel enters a Faulted state + /// + private void FolderClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"FolderClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _folderClient = null; + } + + /// + /// Event handler for when the User client channel enters a Faulted state + /// + private void UserClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"UserClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _userClient = null; + } + + /// + /// Event handler for when the UserRole client channel enters a Faulted state + /// + private void UserRoleClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"UserRoleClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _userRoleClient = null; + } + + /// + /// Event handler for when the UserGroup client channel enters a Faulted state + /// + private void UserGroupClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"UserGroupClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _userGroupClient = null; + } + + /// + /// Event handler for when the ListOfValues client channel enters a Faulted state + /// + private void ListOfValuesClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"ListOfValuesClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _listOfValuesClient = null; + } + + /// + /// Event handler for when the PublicationOutput client channel enters a Faulted state + /// + private void PublicationOutputClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"PublicationOutputClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _publicationOutputClient = null; + } + + /// + /// Event handler for when the OutputFormat client channel enters a Faulted state + /// + private void OutputFormatClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"OutputFormatClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _outputFormatClient = null; + } + + /// + /// Event handler for when the Settings client channel enters a Faulted state + /// + private void SettingsClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"SettingsClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _settingsClient = null; + } + + /// + /// Event handler for when the EDT client channel enters a Faulted state + /// + private void EDTClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"EDTClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _EDTClient = null; + } + + /// + /// Event handler for when the EventMonitor client channel enters a Faulted state + /// + private void EventMonitorClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"EventMonitorClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _eventMonitorClient = null; + } + + /// + /// Event handler for when the Baseline client channel enters a Faulted state + /// + private void BaselineClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"BaselineClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _baselineClient = null; + } + + /// + /// Event handler for when the MetadataBinding client channel enters a Faulted state + /// + private void MetadataBindingClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"MetadataBindingClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _metadataBindingClient = null; + } + + /// + /// Event handler for when the Search client channel enters a Faulted state + /// + private void SearchClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"SearchClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _searchClient = null; + } + + /// + /// Event handler for when the TranslationJob client channel enters a Faulted state + /// + private void TranslationJobClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"TranslationJobClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _translationJobClient = null; + } + + /// + /// Event handler for when the TranslationTemplate client channel enters a Faulted state + /// + private void TranslationTemplateClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"TranslationTemplateClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _translationTemplateClient = null; + } + + /// + /// Event handler for when the BackgroundTask client channel enters a Faulted state + /// + private void BackgroundTaskClientChannelFaulted(object sender, EventArgs e) + { + _logger.WriteDebug($"BackgroundTaskClientChannelFaulted State[{((ICommunicationObject)sender)?.State}]"); + ((ICommunicationObject)sender)?.Abort(); + _backgroundTaskClient = null; + } + #endregion Private Faulted Event Handlers + #region Public Get..Channel Methods /// /// Create a /Wcf/API25/Annotation.svc proxy @@ -350,17 +542,21 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() #if NET48 if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}]"); _annotationClient = new Annotation25ServiceReference.AnnotationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Annotation25])); + ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); } return _annotationClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}]"); _annotationClient = new Annotation25ServiceReference.AnnotationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Annotation25])); + ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); } _annotationClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _annotationClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; @@ -385,17 +581,21 @@ public Application25ServiceReference.Application GetApplication25Channel() #if NET48 if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}]"); _applicationClient = new Application25ServiceReference.ApplicationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Application25])); + ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); } return _applicationClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}]"); _applicationClient = new Application25ServiceReference.ApplicationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Application25])); + ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); _applicationClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _applicationClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _applicationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -421,17 +621,21 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() #if NET48 if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}]"); _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); + ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); } return _documentObjClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}]"); _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); + ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); _documentObjClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _documentObjClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _documentObjClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -457,17 +661,21 @@ public Folder25ServiceReference.Folder GetFolder25Channel() #if NET48 if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}]"); _folderClient = new Folder25ServiceReference.FolderClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Folder25])); + ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); } return _folderClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}]"); _folderClient = new Folder25ServiceReference.FolderClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Folder25])); + ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); _folderClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _folderClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _folderClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -493,17 +701,21 @@ public User25ServiceReference.User GetUser25Channel() #if NET48 if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}]"); _userClient = new User25ServiceReference.UserClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[User25])); + ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); } return _userClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}]"); _userClient = new User25ServiceReference.UserClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[User25])); + ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); _userClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _userClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _userClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -529,17 +741,21 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() #if NET48 if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}]"); _userRoleClient = new UserRole25ServiceReference.UserRoleClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserRole25])); + ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); } return _userRoleClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}]"); _userRoleClient = new UserRole25ServiceReference.UserRoleClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserRole25])); + ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); _userRoleClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _userRoleClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _userRoleClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -565,17 +781,21 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() #if NET48 if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}]"); _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserGroup25])); + ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); } return _userGroupClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}]"); _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserGroup25])); + ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); _userGroupClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _userGroupClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _userGroupClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -601,17 +821,21 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() #if NET48 if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}]"); _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); + ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); } return _listOfValuesClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}]"); _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); + ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); _listOfValuesClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _listOfValuesClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _listOfValuesClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -637,17 +861,21 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu #if NET48 if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}]"); _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); + ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); } return _publicationOutputClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}]"); _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); + ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); _publicationOutputClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _publicationOutputClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _publicationOutputClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -673,17 +901,21 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() #if NET48 if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}]"); _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); + ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); } return _outputFormatClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}]"); _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); + ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); _outputFormatClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _outputFormatClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _outputFormatClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -709,17 +941,21 @@ public Settings25ServiceReference.Settings GetSettings25Channel() #if NET48 if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}]"); _settingsClient = new Settings25ServiceReference.SettingsClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Settings25])); + ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); } return _settingsClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}]"); _settingsClient = new Settings25ServiceReference.SettingsClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Settings25])); + ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); _settingsClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _settingsClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _settingsClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -745,17 +981,21 @@ public EDT25ServiceReference.EDT GetEDT25Channel() #if NET48 if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}]"); _EDTClient = new EDT25ServiceReference.EDTClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EDT25])); + ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); } return _EDTClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}]"); _EDTClient = new EDT25ServiceReference.EDTClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EDT25])); + ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); _EDTClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _EDTClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _EDTClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -781,17 +1021,21 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() #if NET48 if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}]"); _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); + ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); } return _eventMonitorClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}]"); _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); + ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); _eventMonitorClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _eventMonitorClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _eventMonitorClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -817,17 +1061,21 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() #if NET48 if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}]"); _baselineClient = new Baseline25ServiceReference.BaselineClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Baseline25])); + ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); } return _baselineClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}]"); _baselineClient = new Baseline25ServiceReference.BaselineClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Baseline25])); + ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); _baselineClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _baselineClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _baselineClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -853,17 +1101,21 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha #if NET48 if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}]"); _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); + ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); } return _metadataBindingClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}]"); _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); + ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); _metadataBindingClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _metadataBindingClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _metadataBindingClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -889,17 +1141,21 @@ public Search25ServiceReference.Search GetSearch25Channel() #if NET48 if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}]"); _searchClient = new Search25ServiceReference.SearchClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Search25])); + ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); } return _searchClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}]"); _searchClient = new Search25ServiceReference.SearchClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Search25])); + ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); _searchClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _searchClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _searchClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -925,17 +1181,21 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe #if NET48 if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}]"); _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); + ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); } return _translationJobClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}]"); _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); + ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); _translationJobClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _translationJobClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _translationJobClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -961,17 +1221,21 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT #if NET48 if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}]"); _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); + ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); } return _translationTemplateClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}]"); _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); + ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); _translationTemplateClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _translationTemplateClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _translationTemplateClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -998,17 +1262,21 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe #if NET48 if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}]"); _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); + ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); } return _backgroundTaskClient.ChannelFactory.CreateChannelWithIssuedToken(IssuedToken); #else if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}]"); _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); + ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); _backgroundTaskClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _backgroundTaskClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _backgroundTaskClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; From 23c0993374a2384622b450bd5d6f2f59b69536d0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Oct 2025 10:08:01 +0000 Subject: [PATCH 3/4] Address PR feedback: improve debug logging and clean up README - Remove TokenRefreshed from debug statements (always false due to if clause check) - Rename 'Client' to 'ClientInnerChannelState' in all debug logs (76 locations) - Rename 'ServiceRef' to 'ServiceReferenceState' in OpenIdConnect debug logs (38 locations) - Remove ISHDeploy bullet point from README.MD known issues section Co-authored-by: ddemeyer <19798225+ddemeyer@users.noreply.github.com> --- README.MD | 1 - ...ShareWcfSoapWithOpenIdConnectConnection.cs | 76 +++++++++---------- .../InfoShareWcfSoapWithWsTrustConnection.cs | 76 +++++++++---------- 3 files changed, 76 insertions(+), 77 deletions(-) diff --git a/README.MD b/README.MD index fbdb5c6c..94de0397 100644 --- a/README.MD +++ b/README.MD @@ -65,7 +65,6 @@ Any feedback is welcome. Please log a GitHub issue, make sure you submit your ve * If a `New-IshSession -IshUserName ...` results in `System.ServiceModel.FaultException` followed by `An error occurred when verifying security for the message.`, then you are using `-Protocol WcfSoapWithWsTrust` implicitly. A very likely candidate is that deprecated `/ISHSTS/` which authenticates the WS-Federation protocol was not part of your certificate rollover. A simple workaround is to stop the ISHSTS IIS App Pool, delete `\Web\InfoShareSTS\App_Data\IdentityServerConfiguration-2.3.sdf` and in turn start the IIS App Pool again - which will regenerate the local .sdf database. * If you get `You cannot call a method on a null-valued expression.` or `The HTTP status code of the response was not expected (401).`, probably while using `$ishSession.OpenApiISH30Client` it means your token expired and requires a refresh. * If you get `New-IshSession : Reference to undeclared entity 'raquo'. Line 98, position 121.`, most likely you specified an unexisting "Web Services API" url. Make sure your url ends with an ending slash `/`. -* ISHDeploy `Enable-ISHIntegrationSTSInternalAuthentication/Disable-ISHIntegrationSTSInternalAuthentication` adds a /ISHWS/Internal/connectionconfiguration.xml that a different issuer should be used. As ISHRemote doesn't have an app.config, all the artifacts are derived from the RelyingParty WSDL provided mex endpoint (e.g. /ISHSTS/issue/wstrust/mex). # Standards To Respect diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs index 749dabad..81da589a 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs @@ -537,7 +537,7 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_annotationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}] ServiceRef[{(_annotationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetAnnotation25Channel recreating client - ClientInnerChannelState[{_annotationClient?.InnerChannel?.State}] ServiceReferenceState[{(_annotationServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_annotationClient)?.Dispose(); ((IDisposable)_annotationServiceReference)?.Dispose(); _annotationClient = new Annotation25ServiceReference.AnnotationClient( @@ -551,7 +551,7 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_annotationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}] ServiceRef[{(_annotationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetAnnotation25Channel recreating client - ClientInnerChannelState[{_annotationClient?.InnerChannel?.State}] ServiceReferenceState[{(_annotationServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_annotationClient)?.Dispose(); ((IDisposable)_annotationServiceReference)?.Dispose(); _annotationClient = new Annotation25ServiceReference.AnnotationClient( @@ -588,7 +588,7 @@ public Application25ServiceReference.Application GetApplication25Channel() if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_applicationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}] ServiceRef[{(_applicationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetApplication25Channel recreating client - ClientInnerChannelState[{_applicationClient?.InnerChannel?.State}] ServiceReferenceState[{(_applicationServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_applicationClient)?.Dispose(); ((IDisposable)_applicationServiceReference)?.Dispose(); _applicationClient = new Application25ServiceReference.ApplicationClient( @@ -602,7 +602,7 @@ public Application25ServiceReference.Application GetApplication25Channel() if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_applicationServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}] ServiceRef[{(_applicationServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetApplication25Channel recreating client - ClientInnerChannelState[{_applicationClient?.InnerChannel?.State}] ServiceReferenceState[{(_applicationServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_applicationClient)?.Dispose(); ((IDisposable)_applicationServiceReference)?.Dispose(); _applicationClient = new Application25ServiceReference.ApplicationClient( @@ -640,7 +640,7 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_documentObjServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}] ServiceRef[{(_documentObjServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - ClientInnerChannelState[{_documentObjClient?.InnerChannel?.State}] ServiceReferenceState[{(_documentObjServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_documentObjClient)?.Dispose(); ((IDisposable)_documentObjServiceReference)?.Dispose(); _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( @@ -654,7 +654,7 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_documentObjServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}] ServiceRef[{(_documentObjServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - ClientInnerChannelState[{_documentObjClient?.InnerChannel?.State}] ServiceReferenceState[{(_documentObjServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_documentObjClient)?.Dispose(); ((IDisposable)_documentObjServiceReference)?.Dispose(); _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( @@ -691,7 +691,7 @@ public Folder25ServiceReference.Folder GetFolder25Channel() if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_folderServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}] ServiceRef[{(_folderServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetFolder25Channel recreating client - ClientInnerChannelState[{_folderClient?.InnerChannel?.State}] ServiceReferenceState[{(_folderServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_folderClient)?.Dispose(); ((IDisposable)_folderServiceReference)?.Dispose(); _folderClient = new Folder25ServiceReference.FolderClient( @@ -705,7 +705,7 @@ public Folder25ServiceReference.Folder GetFolder25Channel() if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_folderServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}] ServiceRef[{(_folderServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetFolder25Channel recreating client - ClientInnerChannelState[{_folderClient?.InnerChannel?.State}] ServiceReferenceState[{(_folderServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_folderClient)?.Dispose(); ((IDisposable)_folderServiceReference)?.Dispose(); _folderClient = new Folder25ServiceReference.FolderClient( @@ -742,7 +742,7 @@ public User25ServiceReference.User GetUser25Channel() if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_userServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}] ServiceRef[{(_userServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetUser25Channel recreating client - ClientInnerChannelState[{_userClient?.InnerChannel?.State}] ServiceReferenceState[{(_userServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_userClient)?.Dispose(); ((IDisposable)_userServiceReference)?.Dispose(); _userClient = new User25ServiceReference.UserClient( @@ -756,7 +756,7 @@ public User25ServiceReference.User GetUser25Channel() if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_userServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}] ServiceRef[{(_userServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetUser25Channel recreating client - ClientInnerChannelState[{_userClient?.InnerChannel?.State}] ServiceReferenceState[{(_userServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_userClient)?.Dispose(); ((IDisposable)_userServiceReference)?.Dispose(); _userClient = new User25ServiceReference.UserClient( @@ -793,7 +793,7 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_userRoleServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}] ServiceRef[{(_userRoleServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetUserRole25Channel recreating client - ClientInnerChannelState[{_userRoleClient?.InnerChannel?.State}] ServiceReferenceState[{(_userRoleServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_userRoleClient)?.Dispose(); ((IDisposable)_userRoleServiceReference)?.Dispose(); _userRoleClient = new UserRole25ServiceReference.UserRoleClient( @@ -807,7 +807,7 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_userRoleServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}] ServiceRef[{(_userRoleServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetUserRole25Channel recreating client - ClientInnerChannelState[{_userRoleClient?.InnerChannel?.State}] ServiceReferenceState[{(_userRoleServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_userRoleClient)?.Dispose(); ((IDisposable)_userRoleServiceReference)?.Dispose(); _userRoleClient = new UserRole25ServiceReference.UserRoleClient( @@ -844,7 +844,7 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_userGroupServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}] ServiceRef[{(_userGroupServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetUserGroup25Channel recreating client - ClientInnerChannelState[{_userGroupClient?.InnerChannel?.State}] ServiceReferenceState[{(_userGroupServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_userGroupClient)?.Dispose(); ((IDisposable)_userGroupServiceReference)?.Dispose(); _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( @@ -858,7 +858,7 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_userGroupServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}] ServiceRef[{(_userGroupServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetUserGroup25Channel recreating client - ClientInnerChannelState[{_userGroupClient?.InnerChannel?.State}] ServiceReferenceState[{(_userGroupServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_userGroupClient)?.Dispose(); ((IDisposable)_userGroupServiceReference)?.Dispose(); _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( @@ -895,7 +895,7 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_listOfValuesServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}] ServiceRef[{(_listOfValuesServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetListOfValues25Channel recreating client - ClientInnerChannelState[{_listOfValuesClient?.InnerChannel?.State}] ServiceReferenceState[{(_listOfValuesServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_listOfValuesClient)?.Dispose(); ((IDisposable)_listOfValuesServiceReference)?.Dispose(); _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( @@ -909,7 +909,7 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_listOfValuesServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}] ServiceRef[{(_listOfValuesServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetListOfValues25Channel recreating client - ClientInnerChannelState[{_listOfValuesClient?.InnerChannel?.State}] ServiceReferenceState[{(_listOfValuesServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_listOfValuesClient)?.Dispose(); ((IDisposable)_listOfValuesServiceReference)?.Dispose(); _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( @@ -946,7 +946,7 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_publicationOutputServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}] ServiceRef[{(_publicationOutputServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - ClientInnerChannelState[{_publicationOutputClient?.InnerChannel?.State}] ServiceReferenceState[{(_publicationOutputServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_publicationOutputClient)?.Dispose(); ((IDisposable)_publicationOutputServiceReference)?.Dispose(); _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( @@ -960,7 +960,7 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_publicationOutputServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}] ServiceRef[{(_publicationOutputServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - ClientInnerChannelState[{_publicationOutputClient?.InnerChannel?.State}] ServiceReferenceState[{(_publicationOutputServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_publicationOutputClient)?.Dispose(); ((IDisposable)_publicationOutputServiceReference)?.Dispose(); _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( @@ -997,7 +997,7 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_outputFormatServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}] ServiceRef[{(_outputFormatServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - ClientInnerChannelState[{_outputFormatClient?.InnerChannel?.State}] ServiceReferenceState[{(_outputFormatServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_outputFormatClient)?.Dispose(); ((IDisposable)_outputFormatServiceReference)?.Dispose(); _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( @@ -1011,7 +1011,7 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_outputFormatServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}] ServiceRef[{(_outputFormatServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - ClientInnerChannelState[{_outputFormatClient?.InnerChannel?.State}] ServiceReferenceState[{(_outputFormatServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_outputFormatClient)?.Dispose(); ((IDisposable)_outputFormatServiceReference)?.Dispose(); _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( @@ -1048,7 +1048,7 @@ public Settings25ServiceReference.Settings GetSettings25Channel() if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_settingsServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}] ServiceRef[{(_settingsServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetSettings25Channel recreating client - ClientInnerChannelState[{_settingsClient?.InnerChannel?.State}] ServiceReferenceState[{(_settingsServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_settingsClient)?.Dispose(); ((IDisposable)_settingsServiceReference)?.Dispose(); _settingsClient = new Settings25ServiceReference.SettingsClient( @@ -1062,7 +1062,7 @@ public Settings25ServiceReference.Settings GetSettings25Channel() if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_settingsServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}] ServiceRef[{(_settingsServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetSettings25Channel recreating client - ClientInnerChannelState[{_settingsClient?.InnerChannel?.State}] ServiceReferenceState[{(_settingsServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_settingsClient)?.Dispose(); ((IDisposable)_settingsServiceReference)?.Dispose(); _settingsClient = new Settings25ServiceReference.SettingsClient( @@ -1099,7 +1099,7 @@ public EDT25ServiceReference.EDT GetEDT25Channel() if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_EDTServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}] ServiceRef[{(_EDTServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetEDT25Channel recreating client - ClientInnerChannelState[{_EDTClient?.InnerChannel?.State}] ServiceReferenceState[{(_EDTServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_EDTClient)?.Dispose(); ((IDisposable)_EDTServiceReference)?.Dispose(); _EDTClient = new EDT25ServiceReference.EDTClient( @@ -1113,7 +1113,7 @@ public EDT25ServiceReference.EDT GetEDT25Channel() if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_EDTServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}] ServiceRef[{(_EDTServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetEDT25Channel recreating client - ClientInnerChannelState[{_EDTClient?.InnerChannel?.State}] ServiceReferenceState[{(_EDTServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_EDTClient)?.Dispose(); ((IDisposable)_EDTServiceReference)?.Dispose(); _EDTClient = new EDT25ServiceReference.EDTClient( @@ -1150,7 +1150,7 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_eventMonitorServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}] ServiceRef[{(_eventMonitorServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - ClientInnerChannelState[{_eventMonitorClient?.InnerChannel?.State}] ServiceReferenceState[{(_eventMonitorServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_eventMonitorClient)?.Dispose(); ((IDisposable)_eventMonitorServiceReference)?.Dispose(); _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( @@ -1164,7 +1164,7 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_eventMonitorServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}] ServiceRef[{(_eventMonitorServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - ClientInnerChannelState[{_eventMonitorClient?.InnerChannel?.State}] ServiceReferenceState[{(_eventMonitorServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_eventMonitorClient)?.Dispose(); ((IDisposable)_eventMonitorServiceReference)?.Dispose(); _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( @@ -1201,7 +1201,7 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_baselineServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}] ServiceRef[{(_baselineServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetBaseline25Channel recreating client - ClientInnerChannelState[{_baselineClient?.InnerChannel?.State}] ServiceReferenceState[{(_baselineServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_baselineClient)?.Dispose(); ((IDisposable)_baselineServiceReference)?.Dispose(); _baselineClient = new Baseline25ServiceReference.BaselineClient( @@ -1215,7 +1215,7 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_baselineServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}] ServiceRef[{(_baselineServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetBaseline25Channel recreating client - ClientInnerChannelState[{_baselineClient?.InnerChannel?.State}] ServiceReferenceState[{(_baselineServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_baselineClient)?.Dispose(); ((IDisposable)_baselineServiceReference)?.Dispose(); _baselineClient = new Baseline25ServiceReference.BaselineClient( @@ -1252,7 +1252,7 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_metadataBindingServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}] ServiceRef[{(_metadataBindingServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - ClientInnerChannelState[{_metadataBindingClient?.InnerChannel?.State}] ServiceReferenceState[{(_metadataBindingServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_metadataBindingClient)?.Dispose(); ((IDisposable)_metadataBindingServiceReference)?.Dispose(); _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( @@ -1266,7 +1266,7 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_metadataBindingServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}] ServiceRef[{(_metadataBindingServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - ClientInnerChannelState[{_metadataBindingClient?.InnerChannel?.State}] ServiceReferenceState[{(_metadataBindingServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_metadataBindingClient)?.Dispose(); ((IDisposable)_metadataBindingServiceReference)?.Dispose(); _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( @@ -1303,7 +1303,7 @@ public Search25ServiceReference.Search GetSearch25Channel() if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_searchServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}] ServiceRef[{(_searchServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetSearch25Channel recreating client - ClientInnerChannelState[{_searchClient?.InnerChannel?.State}] ServiceReferenceState[{(_searchServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_searchClient)?.Dispose(); ((IDisposable)_searchServiceReference)?.Dispose(); _searchClient = new Search25ServiceReference.SearchClient( @@ -1317,7 +1317,7 @@ public Search25ServiceReference.Search GetSearch25Channel() if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_searchServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}] ServiceRef[{(_searchServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetSearch25Channel recreating client - ClientInnerChannelState[{_searchClient?.InnerChannel?.State}] ServiceReferenceState[{(_searchServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_searchClient)?.Dispose(); ((IDisposable)_searchServiceReference)?.Dispose(); _searchClient = new Search25ServiceReference.SearchClient( @@ -1354,7 +1354,7 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_translationJobServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}] ServiceRef[{(_translationJobServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - ClientInnerChannelState[{_translationJobClient?.InnerChannel?.State}] ServiceReferenceState[{(_translationJobServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_translationJobClient)?.Dispose(); ((IDisposable)_translationJobServiceReference)?.Dispose(); _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( @@ -1368,7 +1368,7 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_translationJobServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}] ServiceRef[{(_translationJobServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - ClientInnerChannelState[{_translationJobClient?.InnerChannel?.State}] ServiceReferenceState[{(_translationJobServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_translationJobClient)?.Dispose(); ((IDisposable)_translationJobServiceReference)?.Dispose(); _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( @@ -1405,7 +1405,7 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_translationTemplateServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}] ServiceRef[{(_translationTemplateServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - ClientInnerChannelState[{_translationTemplateClient?.InnerChannel?.State}] ServiceReferenceState[{(_translationTemplateServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_translationTemplateClient)?.Dispose(); ((IDisposable)_translationTemplateServiceReference)?.Dispose(); _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( @@ -1419,7 +1419,7 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_translationTemplateServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}] ServiceRef[{(_translationTemplateServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - ClientInnerChannelState[{_translationTemplateClient?.InnerChannel?.State}] ServiceReferenceState[{(_translationTemplateServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_translationTemplateClient)?.Dispose(); ((IDisposable)_translationTemplateServiceReference)?.Dispose(); _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( @@ -1457,7 +1457,7 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_backgroundTaskServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}] ServiceRef[{(_backgroundTaskServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - ClientInnerChannelState[{_backgroundTaskClient?.InnerChannel?.State}] ServiceReferenceState[{(_backgroundTaskServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_backgroundTaskClient)?.Dispose(); ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( @@ -1471,7 +1471,7 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted) || (_backgroundTaskServiceReference == null) || (GetAccessToken().IsAccessTokenRefreshed)) { - _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}] ServiceRef[{(_backgroundTaskServiceReference as ICommunicationObject)?.State}] TokenRefreshed[{GetAccessToken().IsAccessTokenRefreshed}]"); + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - ClientInnerChannelState[{_backgroundTaskClient?.InnerChannel?.State}] ServiceReferenceState[{(_backgroundTaskServiceReference as ICommunicationObject)?.State}]"); ((IDisposable)_backgroundTaskClient)?.Dispose(); ((IDisposable)_backgroundTaskServiceReference)?.Dispose(); _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs index 7f4e55b0..5d05a790 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs @@ -542,7 +542,7 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() #if NET48 if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetAnnotation25Channel recreating client - ClientInnerChannelState[{_annotationClient?.InnerChannel?.State}]"); _annotationClient = new Annotation25ServiceReference.AnnotationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Annotation25])); @@ -552,7 +552,7 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() #else if ((_annotationClient == null) || (_annotationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetAnnotation25Channel recreating client - Client[{_annotationClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetAnnotation25Channel recreating client - ClientInnerChannelState[{_annotationClient?.InnerChannel?.State}]"); _annotationClient = new Annotation25ServiceReference.AnnotationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Annotation25])); @@ -581,7 +581,7 @@ public Application25ServiceReference.Application GetApplication25Channel() #if NET48 if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetApplication25Channel recreating client - ClientInnerChannelState[{_applicationClient?.InnerChannel?.State}]"); _applicationClient = new Application25ServiceReference.ApplicationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Application25])); @@ -591,7 +591,7 @@ public Application25ServiceReference.Application GetApplication25Channel() #else if ((_applicationClient == null) || (_applicationClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetApplication25Channel recreating client - Client[{_applicationClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetApplication25Channel recreating client - ClientInnerChannelState[{_applicationClient?.InnerChannel?.State}]"); _applicationClient = new Application25ServiceReference.ApplicationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Application25])); @@ -621,7 +621,7 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() #if NET48 if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - ClientInnerChannelState[{_documentObjClient?.InnerChannel?.State}]"); _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); @@ -631,7 +631,7 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() #else if ((_documentObjClient == null) || (_documentObjClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetDocumentObj25Channel recreating client - Client[{_documentObjClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetDocumentObj25Channel recreating client - ClientInnerChannelState[{_documentObjClient?.InnerChannel?.State}]"); _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); @@ -661,7 +661,7 @@ public Folder25ServiceReference.Folder GetFolder25Channel() #if NET48 if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetFolder25Channel recreating client - ClientInnerChannelState[{_folderClient?.InnerChannel?.State}]"); _folderClient = new Folder25ServiceReference.FolderClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Folder25])); @@ -671,7 +671,7 @@ public Folder25ServiceReference.Folder GetFolder25Channel() #else if ((_folderClient == null) || (_folderClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetFolder25Channel recreating client - Client[{_folderClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetFolder25Channel recreating client - ClientInnerChannelState[{_folderClient?.InnerChannel?.State}]"); _folderClient = new Folder25ServiceReference.FolderClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Folder25])); @@ -701,7 +701,7 @@ public User25ServiceReference.User GetUser25Channel() #if NET48 if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetUser25Channel recreating client - ClientInnerChannelState[{_userClient?.InnerChannel?.State}]"); _userClient = new User25ServiceReference.UserClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[User25])); @@ -711,7 +711,7 @@ public User25ServiceReference.User GetUser25Channel() #else if ((_userClient == null) || (_userClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetUser25Channel recreating client - Client[{_userClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetUser25Channel recreating client - ClientInnerChannelState[{_userClient?.InnerChannel?.State}]"); _userClient = new User25ServiceReference.UserClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[User25])); @@ -741,7 +741,7 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() #if NET48 if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetUserRole25Channel recreating client - ClientInnerChannelState[{_userRoleClient?.InnerChannel?.State}]"); _userRoleClient = new UserRole25ServiceReference.UserRoleClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserRole25])); @@ -751,7 +751,7 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() #else if ((_userRoleClient == null) || (_userRoleClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetUserRole25Channel recreating client - Client[{_userRoleClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetUserRole25Channel recreating client - ClientInnerChannelState[{_userRoleClient?.InnerChannel?.State}]"); _userRoleClient = new UserRole25ServiceReference.UserRoleClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserRole25])); @@ -781,7 +781,7 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() #if NET48 if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetUserGroup25Channel recreating client - ClientInnerChannelState[{_userGroupClient?.InnerChannel?.State}]"); _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserGroup25])); @@ -791,7 +791,7 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() #else if ((_userGroupClient == null) || (_userGroupClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetUserGroup25Channel recreating client - Client[{_userGroupClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetUserGroup25Channel recreating client - ClientInnerChannelState[{_userGroupClient?.InnerChannel?.State}]"); _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserGroup25])); @@ -821,7 +821,7 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() #if NET48 if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetListOfValues25Channel recreating client - ClientInnerChannelState[{_listOfValuesClient?.InnerChannel?.State}]"); _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); @@ -831,7 +831,7 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() #else if ((_listOfValuesClient == null) || (_listOfValuesClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetListOfValues25Channel recreating client - Client[{_listOfValuesClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetListOfValues25Channel recreating client - ClientInnerChannelState[{_listOfValuesClient?.InnerChannel?.State}]"); _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); @@ -861,7 +861,7 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu #if NET48 if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - ClientInnerChannelState[{_publicationOutputClient?.InnerChannel?.State}]"); _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); @@ -871,7 +871,7 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu #else if ((_publicationOutputClient == null) || (_publicationOutputClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - Client[{_publicationOutputClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetPublicationOutput25Channel recreating client - ClientInnerChannelState[{_publicationOutputClient?.InnerChannel?.State}]"); _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); @@ -901,7 +901,7 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() #if NET48 if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - ClientInnerChannelState[{_outputFormatClient?.InnerChannel?.State}]"); _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); @@ -911,7 +911,7 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() #else if ((_outputFormatClient == null) || (_outputFormatClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetOutputFormat25Channel recreating client - Client[{_outputFormatClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetOutputFormat25Channel recreating client - ClientInnerChannelState[{_outputFormatClient?.InnerChannel?.State}]"); _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); @@ -941,7 +941,7 @@ public Settings25ServiceReference.Settings GetSettings25Channel() #if NET48 if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetSettings25Channel recreating client - ClientInnerChannelState[{_settingsClient?.InnerChannel?.State}]"); _settingsClient = new Settings25ServiceReference.SettingsClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Settings25])); @@ -951,7 +951,7 @@ public Settings25ServiceReference.Settings GetSettings25Channel() #else if ((_settingsClient == null) || (_settingsClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetSettings25Channel recreating client - Client[{_settingsClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetSettings25Channel recreating client - ClientInnerChannelState[{_settingsClient?.InnerChannel?.State}]"); _settingsClient = new Settings25ServiceReference.SettingsClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Settings25])); @@ -981,7 +981,7 @@ public EDT25ServiceReference.EDT GetEDT25Channel() #if NET48 if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetEDT25Channel recreating client - ClientInnerChannelState[{_EDTClient?.InnerChannel?.State}]"); _EDTClient = new EDT25ServiceReference.EDTClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EDT25])); @@ -991,7 +991,7 @@ public EDT25ServiceReference.EDT GetEDT25Channel() #else if ((_EDTClient == null) || (_EDTClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetEDT25Channel recreating client - Client[{_EDTClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetEDT25Channel recreating client - ClientInnerChannelState[{_EDTClient?.InnerChannel?.State}]"); _EDTClient = new EDT25ServiceReference.EDTClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EDT25])); @@ -1021,7 +1021,7 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() #if NET48 if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - ClientInnerChannelState[{_eventMonitorClient?.InnerChannel?.State}]"); _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); @@ -1031,7 +1031,7 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() #else if ((_eventMonitorClient == null) || (_eventMonitorClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetEventMonitor25Channel recreating client - Client[{_eventMonitorClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetEventMonitor25Channel recreating client - ClientInnerChannelState[{_eventMonitorClient?.InnerChannel?.State}]"); _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); @@ -1061,7 +1061,7 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() #if NET48 if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetBaseline25Channel recreating client - ClientInnerChannelState[{_baselineClient?.InnerChannel?.State}]"); _baselineClient = new Baseline25ServiceReference.BaselineClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Baseline25])); @@ -1071,7 +1071,7 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() #else if ((_baselineClient == null) || (_baselineClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetBaseline25Channel recreating client - Client[{_baselineClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetBaseline25Channel recreating client - ClientInnerChannelState[{_baselineClient?.InnerChannel?.State}]"); _baselineClient = new Baseline25ServiceReference.BaselineClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Baseline25])); @@ -1101,7 +1101,7 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha #if NET48 if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - ClientInnerChannelState[{_metadataBindingClient?.InnerChannel?.State}]"); _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); @@ -1111,7 +1111,7 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha #else if ((_metadataBindingClient == null) || (_metadataBindingClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - Client[{_metadataBindingClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetMetadataBinding25Channel recreating client - ClientInnerChannelState[{_metadataBindingClient?.InnerChannel?.State}]"); _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); @@ -1141,7 +1141,7 @@ public Search25ServiceReference.Search GetSearch25Channel() #if NET48 if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetSearch25Channel recreating client - ClientInnerChannelState[{_searchClient?.InnerChannel?.State}]"); _searchClient = new Search25ServiceReference.SearchClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Search25])); @@ -1151,7 +1151,7 @@ public Search25ServiceReference.Search GetSearch25Channel() #else if ((_searchClient == null) || (_searchClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetSearch25Channel recreating client - Client[{_searchClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetSearch25Channel recreating client - ClientInnerChannelState[{_searchClient?.InnerChannel?.State}]"); _searchClient = new Search25ServiceReference.SearchClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Search25])); @@ -1181,7 +1181,7 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe #if NET48 if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - ClientInnerChannelState[{_translationJobClient?.InnerChannel?.State}]"); _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); @@ -1191,7 +1191,7 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe #else if ((_translationJobClient == null) || (_translationJobClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetTranslationJob25Channel recreating client - Client[{_translationJobClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetTranslationJob25Channel recreating client - ClientInnerChannelState[{_translationJobClient?.InnerChannel?.State}]"); _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); @@ -1221,7 +1221,7 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT #if NET48 if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - ClientInnerChannelState[{_translationTemplateClient?.InnerChannel?.State}]"); _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); @@ -1231,7 +1231,7 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT #else if ((_translationTemplateClient == null) || (_translationTemplateClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - Client[{_translationTemplateClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetTranslationTemplate25Channel recreating client - ClientInnerChannelState[{_translationTemplateClient?.InnerChannel?.State}]"); _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); @@ -1262,7 +1262,7 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe #if NET48 if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - ClientInnerChannelState[{_backgroundTaskClient?.InnerChannel?.State}]"); _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); @@ -1272,7 +1272,7 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe #else if ((_backgroundTaskClient == null) || (_backgroundTaskClient.InnerChannel.State == System.ServiceModel.CommunicationState.Faulted)) { - _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - Client[{_backgroundTaskClient?.InnerChannel?.State}]"); + _logger.WriteDebug($"GetBackgroundTask25Channel recreating client - ClientInnerChannelState[{_backgroundTaskClient?.InnerChannel?.State}]"); _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); From 7f4c03f739aff787bdf451c8ccb7a67bf1f082a2 Mon Sep 17 00:00:00 2001 From: ddemeyer Date: Wed, 15 Oct 2025 20:09:58 +0200 Subject: [PATCH 4/4] #214 Mostly implemented by copilot although theoretical leading to PS7/NET6+ runtime error "Object is read-only." found during Pester Tests. This is caused by assigning the EventHandler which finishes initialization before setting "CertificateValidationMode", which in turn causes "X509ServiceCertificateAuthentication.ThrowIfImmutable". Changed the order. --- ...ShareWcfSoapWithOpenIdConnectConnection.cs | 40 ++++++------- .../InfoShareWcfSoapWithWsTrustConnection.cs | 58 +++++++++---------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs index 81da589a..a694f169 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithOpenIdConnectConnection.cs @@ -558,8 +558,6 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() _commonBinding, new EndpointAddress(_serviceUriByServiceName[Annotation25])); - ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); - _annotationClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_annotationClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); _annotationClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); @@ -573,6 +571,7 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); _annotationServiceReference = _annotationClient.ChannelFactory.CreateChannel(); } return _annotationServiceReference; @@ -609,8 +608,6 @@ public Application25ServiceReference.Application GetApplication25Channel() _commonBinding, new EndpointAddress(_serviceUriByServiceName[Application25])); - ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); - _applicationClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_applicationClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); _applicationClient.ChannelFactory.Endpoint.EndpointBehaviors.Add(bearerCredentials); @@ -624,6 +621,7 @@ public Application25ServiceReference.Application GetApplication25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); _applicationServiceReference = _applicationClient.ChannelFactory.CreateChannel(); } return _applicationServiceReference; @@ -660,7 +658,6 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); - ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); _documentObjClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_documentObjClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -675,6 +672,7 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); _documentObjServiceReference = _documentObjClient.ChannelFactory.CreateChannel(); } return _documentObjServiceReference; @@ -711,7 +709,6 @@ public Folder25ServiceReference.Folder GetFolder25Channel() _folderClient = new Folder25ServiceReference.FolderClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Folder25])); - ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); _folderClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_folderClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -726,6 +723,7 @@ public Folder25ServiceReference.Folder GetFolder25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); _folderServiceReference = _folderClient.ChannelFactory.CreateChannel(); } return _folderServiceReference; @@ -762,7 +760,6 @@ public User25ServiceReference.User GetUser25Channel() _userClient = new User25ServiceReference.UserClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[User25])); - ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); _userClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -777,6 +774,7 @@ public User25ServiceReference.User GetUser25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); _userServiceReference = _userClient.ChannelFactory.CreateChannel(); } return _userServiceReference; @@ -813,7 +811,6 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() _userRoleClient = new UserRole25ServiceReference.UserRoleClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserRole25])); - ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); _userRoleClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userRoleClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -828,6 +825,7 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); _userRoleServiceReference = _userRoleClient.ChannelFactory.CreateChannel(); } return _userRoleServiceReference; @@ -864,7 +862,6 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserGroup25])); - ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); _userGroupClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_userGroupClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -879,6 +876,7 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); _userGroupServiceReference = _userGroupClient.ChannelFactory.CreateChannel(); } return _userGroupServiceReference; @@ -915,7 +913,6 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); - ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); _listOfValuesClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_listOfValuesClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -930,6 +927,7 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); _listOfValuesServiceReference = _listOfValuesClient.ChannelFactory.CreateChannel(); } return _listOfValuesServiceReference; @@ -966,7 +964,6 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); - ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); _publicationOutputClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_publicationOutputClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -981,6 +978,7 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); _publicationOutputServiceReference = _publicationOutputClient.ChannelFactory.CreateChannel(); } return _publicationOutputServiceReference; @@ -1017,7 +1015,6 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); - ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); _outputFormatClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_outputFormatClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1032,6 +1029,7 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); _outputFormatServiceReference = _outputFormatClient.ChannelFactory.CreateChannel(); } return _outputFormatServiceReference; @@ -1068,7 +1066,6 @@ public Settings25ServiceReference.Settings GetSettings25Channel() _settingsClient = new Settings25ServiceReference.SettingsClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Settings25])); - ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); _settingsClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_settingsClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1083,6 +1080,7 @@ public Settings25ServiceReference.Settings GetSettings25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); _settingsServiceReference = _settingsClient.ChannelFactory.CreateChannel(); } return _settingsServiceReference; @@ -1119,7 +1117,6 @@ public EDT25ServiceReference.EDT GetEDT25Channel() _EDTClient = new EDT25ServiceReference.EDTClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EDT25])); - ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); _EDTClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_EDTClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1134,6 +1131,7 @@ public EDT25ServiceReference.EDT GetEDT25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); _EDTServiceReference = _EDTClient.ChannelFactory.CreateChannel(); } return _EDTServiceReference; @@ -1170,7 +1168,6 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); - ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); _eventMonitorClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_eventMonitorClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1185,6 +1182,7 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); _eventMonitorServiceReference = _eventMonitorClient.ChannelFactory.CreateChannel(); } return _eventMonitorServiceReference; @@ -1221,7 +1219,6 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() _baselineClient = new Baseline25ServiceReference.BaselineClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Baseline25])); - ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); _baselineClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_baselineClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1236,6 +1233,7 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); _baselineServiceReference = _baselineClient.ChannelFactory.CreateChannel(); } return _baselineServiceReference; @@ -1272,7 +1270,6 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); - ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); _metadataBindingClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_metadataBindingClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1287,6 +1284,7 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); _metadataBindingServiceReference = _metadataBindingClient.ChannelFactory.CreateChannel(); } return _metadataBindingServiceReference; @@ -1323,7 +1321,6 @@ public Search25ServiceReference.Search GetSearch25Channel() _searchClient = new Search25ServiceReference.SearchClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Search25])); - ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); _searchClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_searchClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1338,6 +1335,7 @@ public Search25ServiceReference.Search GetSearch25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); _searchServiceReference = _searchClient.ChannelFactory.CreateChannel(); } return _searchServiceReference; @@ -1374,7 +1372,6 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); - ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); _translationJobClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_translationJobClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1389,6 +1386,7 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); _translationJobServiceReference = _translationJobClient.ChannelFactory.CreateChannel(); } return _translationJobServiceReference; @@ -1425,7 +1423,6 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); - ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); _translationTemplateClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_translationTemplateClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1440,6 +1437,7 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); _translationTemplateServiceReference = _translationTemplateClient.ChannelFactory.CreateChannel(); } return _translationTemplateServiceReference; @@ -1477,7 +1475,6 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); - ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); _backgroundTaskClient.ChannelFactory.Endpoint.EndpointBehaviors.Remove(_backgroundTaskClient.ChannelFactory.Credentials); var bearerCredentials = GetBearerCredentials(); @@ -1492,6 +1489,7 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); _backgroundTaskServiceReference = _backgroundTaskClient.ChannelFactory.CreateChannel(); } return _backgroundTaskServiceReference; diff --git a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs index 5d05a790..fff726e0 100644 --- a/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs +++ b/Source/ISHRemote/Trisoft.ISHRemote/Connection/InfoShareWcfSoapWithWsTrustConnection.cs @@ -556,18 +556,18 @@ public Annotation25ServiceReference.Annotation GetAnnotation25Channel() _annotationClient = new Annotation25ServiceReference.AnnotationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Annotation25])); - ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); - } - _annotationClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; - _annotationClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; - _annotationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; - if (_connectionParameters.IgnoreSslPolicyErrors) - { - _annotationClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + _annotationClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; + _annotationClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; + _annotationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; + if (_connectionParameters.IgnoreSslPolicyErrors) { - CertificateValidationMode = X509CertificateValidationMode.None, - RevocationMode = X509RevocationMode.NoCheck - }; + _annotationClient.ChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() + { + CertificateValidationMode = X509CertificateValidationMode.None, + RevocationMode = X509RevocationMode.NoCheck + }; + } + ((ICommunicationObject)_annotationClient).Faulted += new EventHandler(AnnotationClientChannelFaulted); } return _annotationClient.ChannelFactory.CreateChannel(); #endif @@ -595,7 +595,6 @@ public Application25ServiceReference.Application GetApplication25Channel() _applicationClient = new Application25ServiceReference.ApplicationClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Application25])); - ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); _applicationClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _applicationClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _applicationClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -607,6 +606,7 @@ public Application25ServiceReference.Application GetApplication25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_applicationClient).Faulted += new EventHandler(ApplicationClientChannelFaulted); } return _applicationClient.ChannelFactory.CreateChannel(); #endif @@ -635,7 +635,6 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() _documentObjClient = new DocumentObj25ServiceReference.DocumentObjClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[DocumentObj25])); - ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); _documentObjClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _documentObjClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _documentObjClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -647,6 +646,7 @@ public DocumentObj25ServiceReference.DocumentObj GetDocumentObj25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_documentObjClient).Faulted += new EventHandler(DocumentObjClientChannelFaulted); } return _documentObjClient.ChannelFactory.CreateChannel(); #endif @@ -675,7 +675,6 @@ public Folder25ServiceReference.Folder GetFolder25Channel() _folderClient = new Folder25ServiceReference.FolderClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Folder25])); - ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); _folderClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _folderClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _folderClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -687,6 +686,7 @@ public Folder25ServiceReference.Folder GetFolder25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_folderClient).Faulted += new EventHandler(FolderClientChannelFaulted); } return _folderClient.ChannelFactory.CreateChannel(); #endif @@ -715,7 +715,6 @@ public User25ServiceReference.User GetUser25Channel() _userClient = new User25ServiceReference.UserClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[User25])); - ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); _userClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _userClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _userClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -727,6 +726,7 @@ public User25ServiceReference.User GetUser25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_userClient).Faulted += new EventHandler(UserClientChannelFaulted); } return _userClient.ChannelFactory.CreateChannel(); #endif @@ -755,7 +755,6 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() _userRoleClient = new UserRole25ServiceReference.UserRoleClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserRole25])); - ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); _userRoleClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _userRoleClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _userRoleClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -767,6 +766,7 @@ public UserRole25ServiceReference.UserRole GetUserRole25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_userRoleClient).Faulted += new EventHandler(UserRoleClientChannelFaulted); } return _userRoleClient.ChannelFactory.CreateChannel(); #endif @@ -795,7 +795,6 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() _userGroupClient = new UserGroup25ServiceReference.UserGroupClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[UserGroup25])); - ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); _userGroupClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _userGroupClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _userGroupClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -807,6 +806,7 @@ public UserGroup25ServiceReference.UserGroup GetUserGroup25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_userGroupClient).Faulted += new EventHandler(UserGroupClientChannelFaulted); } return _userGroupClient.ChannelFactory.CreateChannel(); #endif @@ -835,7 +835,6 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() _listOfValuesClient = new ListOfValues25ServiceReference.ListOfValuesClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[ListOfValues25])); - ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); _listOfValuesClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _listOfValuesClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _listOfValuesClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -847,6 +846,7 @@ public ListOfValues25ServiceReference.ListOfValues GetListOfValues25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_listOfValuesClient).Faulted += new EventHandler(ListOfValuesClientChannelFaulted); } return _listOfValuesClient.ChannelFactory.CreateChannel(); #endif @@ -875,7 +875,6 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu _publicationOutputClient = new PublicationOutput25ServiceReference.PublicationOutputClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[PublicationOutput25])); - ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); _publicationOutputClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _publicationOutputClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _publicationOutputClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -888,6 +887,7 @@ public PublicationOutput25ServiceReference.PublicationOutput GetPublicationOutpu }; } } + ((ICommunicationObject)_publicationOutputClient).Faulted += new EventHandler(PublicationOutputClientChannelFaulted); return _publicationOutputClient.ChannelFactory.CreateChannel(); #endif } @@ -915,7 +915,6 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() _outputFormatClient = new OutputFormat25ServiceReference.OutputFormatClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[OutputFormat25])); - ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); _outputFormatClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _outputFormatClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _outputFormatClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -927,6 +926,7 @@ public OutputFormat25ServiceReference.OutputFormat GetOutputFormat25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_outputFormatClient).Faulted += new EventHandler(OutputFormatClientChannelFaulted); } return _outputFormatClient.ChannelFactory.CreateChannel(); #endif @@ -955,7 +955,6 @@ public Settings25ServiceReference.Settings GetSettings25Channel() _settingsClient = new Settings25ServiceReference.SettingsClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Settings25])); - ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); _settingsClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _settingsClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _settingsClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -967,6 +966,7 @@ public Settings25ServiceReference.Settings GetSettings25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_settingsClient).Faulted += new EventHandler(SettingsClientChannelFaulted); } return _settingsClient.ChannelFactory.CreateChannel(); #endif @@ -995,7 +995,6 @@ public EDT25ServiceReference.EDT GetEDT25Channel() _EDTClient = new EDT25ServiceReference.EDTClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EDT25])); - ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); _EDTClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _EDTClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _EDTClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1007,6 +1006,7 @@ public EDT25ServiceReference.EDT GetEDT25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_EDTClient).Faulted += new EventHandler(EDTClientChannelFaulted); } return _EDTClient.ChannelFactory.CreateChannel(); #endif @@ -1035,7 +1035,6 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() _eventMonitorClient = new EventMonitor25ServiceReference.EventMonitorClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[EventMonitor25])); - ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); _eventMonitorClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _eventMonitorClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _eventMonitorClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1047,6 +1046,7 @@ public EventMonitor25ServiceReference.EventMonitor GetEventMonitor25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_eventMonitorClient).Faulted += new EventHandler(EventMonitorClientChannelFaulted); } return _eventMonitorClient.ChannelFactory.CreateChannel(); #endif @@ -1075,7 +1075,6 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() _baselineClient = new Baseline25ServiceReference.BaselineClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Baseline25])); - ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); _baselineClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _baselineClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _baselineClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1087,6 +1086,7 @@ public Baseline25ServiceReference.Baseline GetBaseline25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_baselineClient).Faulted += new EventHandler(BaselineClientChannelFaulted); } return _baselineClient.ChannelFactory.CreateChannel(); #endif @@ -1115,7 +1115,6 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha _metadataBindingClient = new MetadataBinding25ServiceReference.MetadataBindingClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[MetadataBinding25])); - ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); _metadataBindingClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _metadataBindingClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _metadataBindingClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1127,6 +1126,7 @@ public MetadataBinding25ServiceReference.MetadataBinding GetMetadataBinding25Cha RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_metadataBindingClient).Faulted += new EventHandler(MetadataBindingClientChannelFaulted); } return _metadataBindingClient.ChannelFactory.CreateChannel(); #endif @@ -1155,7 +1155,6 @@ public Search25ServiceReference.Search GetSearch25Channel() _searchClient = new Search25ServiceReference.SearchClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[Search25])); - ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); _searchClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _searchClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _searchClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1167,6 +1166,7 @@ public Search25ServiceReference.Search GetSearch25Channel() RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_searchClient).Faulted += new EventHandler(SearchClientChannelFaulted); } return _searchClient.ChannelFactory.CreateChannel(); #endif @@ -1195,7 +1195,6 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe _translationJobClient = new TranslationJob25ServiceReference.TranslationJobClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationJob25])); - ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); _translationJobClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _translationJobClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _translationJobClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1207,6 +1206,7 @@ public TranslationJob25ServiceReference.TranslationJob GetTranslationJob25Channe RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_translationJobClient).Faulted += new EventHandler(TranslationJobClientChannelFaulted); } return _translationJobClient.ChannelFactory.CreateChannel(); #endif @@ -1235,7 +1235,6 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT _translationTemplateClient = new TranslationTemplate25ServiceReference.TranslationTemplateClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[TranslationTemplate25])); - ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); _translationTemplateClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _translationTemplateClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _translationTemplateClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1247,6 +1246,7 @@ public TranslationTemplate25ServiceReference.TranslationTemplate GetTranslationT RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_translationTemplateClient).Faulted += new EventHandler(TranslationTemplateClientChannelFaulted); } return _translationTemplateClient.ChannelFactory.CreateChannel(); #endif @@ -1276,7 +1276,6 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe _backgroundTaskClient = new BackgroundTask25ServiceReference.BackgroundTaskClient( _commonBinding, new EndpointAddress(_serviceUriByServiceName[BackgroundTask25])); - ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); _backgroundTaskClient.ClientCredentials.UserName.UserName = _connectionParameters.Credential.UserName; _backgroundTaskClient.ClientCredentials.UserName.Password = _connectionParameters.Credential.Password; _backgroundTaskClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; @@ -1288,6 +1287,7 @@ public BackgroundTask25ServiceReference.BackgroundTask GetBackgroundTask25Channe RevocationMode = X509RevocationMode.NoCheck }; } + ((ICommunicationObject)_backgroundTaskClient).Faulted += new EventHandler(BackgroundTaskClientChannelFaulted); } return _backgroundTaskClient.ChannelFactory.CreateChannel(); #endif