/// <summary> /// Initializes a new instance of the <see cref="SoapPatientService"/> class. /// Constructor that requires an IEndpointBehavior for dependency injection. /// </summary> /// <param name="logger">The service Logger.</param> /// <param name="configuration">The service configuration.</param> /// <param name="loggingEndpointBehaviour">Endpoint behaviour for logging purposes.</param> public SoapPatientService(ILogger <SoapPatientService> logger, IConfiguration configuration, IEndpointBehavior loggingEndpointBehaviour) { if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } this.loggingEndpointBehaviour = loggingEndpointBehaviour; this.logger = logger; IConfigurationSection clientConfiguration = configuration.GetSection("ClientRegistries"); // Load Certificate string clientCertificatePath = clientConfiguration.GetSection("ClientCertificate").GetValue <string>("Path"); string certificatePassword = clientConfiguration.GetSection("ClientCertificate").GetValue <string>("Password"); X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(clientCertificatePath), certificatePassword); string serviceUrl = clientConfiguration.GetValue <string>("ServiceUrl"); EndpointAddress endpoint = new EndpointAddress(new Uri(serviceUrl)); // Create client this.getDemographicsClient = new QUPA_AR101102_PortTypeClient(QUPA_AR101102_PortTypeClient.EndpointConfiguration.QUPA_AR101102_Port, endpoint); this.getDemographicsClient.Endpoint.EndpointBehaviors.Add(this.loggingEndpointBehaviour); this.getDemographicsClient.ClientCredentials.ClientCertificate.Certificate = clientCertificate; // TODO: - HACK - Remove this once we can get the server certificate to be trusted. this.getDemographicsClient.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() { CertificateValidationMode = X509CertificateValidationMode.None, RevocationMode = X509RevocationMode.NoCheck, }; }
/// <summary> /// Configures the ability to use Patient services. /// </summary> /// <param name="services">The service collection to add forward proxies into.</param> public void ConfigurePatientAccess(IServiceCollection services) { services.AddTransient <IEndpointBehavior, LoggingEndpointBehaviour>(); services.AddTransient <IClientMessageInspector, LoggingMessageInspector>(); services.AddTransient <QUPA_AR101102_PortType>(s => { IConfigurationSection clientConfiguration = this.configuration.GetSection("PatientService:ClientRegistry"); EndpointAddress clientRegistriesEndpoint = new EndpointAddress(new Uri(clientConfiguration.GetValue <string>("ServiceUrl"))); // Load Certificate, Note: As per reading we do not have to dispose of the certificate. string clientCertificatePath = clientConfiguration.GetSection("ClientCertificate").GetValue <string>("Path"); string certificatePassword = clientConfiguration.GetSection("ClientCertificate").GetValue <string>("Password"); X509Certificate2 clientRegistriesCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(clientCertificatePath), certificatePassword); QUPA_AR101102_PortTypeClient client = new QUPA_AR101102_PortTypeClient( QUPA_AR101102_PortTypeClient.EndpointConfiguration.QUPA_AR101102_Port, clientRegistriesEndpoint); client.ClientCredentials.ClientCertificate.Certificate = clientRegistriesCertificate; client.Endpoint.EndpointBehaviors.Add(s.GetService <IEndpointBehavior>()); // TODO: - HACK - Remove this once we can get the server certificate to be trusted. client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() { CertificateValidationMode = X509CertificateValidationMode.None, RevocationMode = X509RevocationMode.NoCheck, }; return(client); }); services.AddTransient <IClientRegistriesDelegate, ClientRegistriesDelegate>(); services.AddTransient <IPatientService, PatientService>(); services.AddTransient <IGenericCacheDelegate, DBGenericCacheDelegate>(); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">The injected services provider.</param> public void ConfigureServices(IServiceCollection services) { this.startupConfig.ConfigureForwardHeaders(services); this.startupConfig.ConfigureHttpServices(services); this.startupConfig.ConfigureAuditServices(services); this.startupConfig.ConfigureAuthServicesForJwtBearer(services); this.startupConfig.ConfigureAuthorizationServices(services); this.startupConfig.ConfigureSwaggerServices(services); services.AddTransient <IEndpointBehavior, LoggingEndpointBehaviour>(); services.AddTransient <IClientMessageInspector, LoggingMessageInspector>(); services.AddTransient <QUPA_AR101102_PortType>(s => { QUPA_AR101102_PortTypeClient client = new QUPA_AR101102_PortTypeClient( QUPA_AR101102_PortTypeClient.EndpointConfiguration.QUPA_AR101102_Port, this.clientRegistriesEndpoint); client.ClientCredentials.ClientCertificate.Certificate = this.clientRegistriesCertificate; client.Endpoint.EndpointBehaviors.Add(s.GetService <IEndpointBehavior>()); // TODO: - HACK - Remove this once we can get the server certificate to be trusted. client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() { CertificateValidationMode = X509CertificateValidationMode.None, RevocationMode = X509RevocationMode.NoCheck, }; return(client); }); services.AddTransient <IClientRegistriesDelegate, ClientRegistriesDelegate>(); services.AddTransient <IPatientService, SoapPatientService>(); services.AddSingleton <ITraceService, TimedTraceService>(); }