Beispiel #1
0
        private async Task <RegiXResponse> CallRegiXAsync(CustomCallContext context, ServiceRequestData request)
        {
            try
            {
                RegiXEntryPointClient client = CreateRegiXEntryPointClient();

                // Ако не е подаден сертификат, се използва този от конфигурационния файл.
                X509CertificateInitiatorClientCredential clientCert = client.ClientCredentials.ClientCertificate;
                if (context.Certificate != null)
                {
                    clientCert.Certificate = context.Certificate;
                }
                else if (clientCert.Certificate == null)
                {
                    throw new Exception("Не е указан сертификат за достъп до RegiX.");
                }

                Log.Information($"IntegrationService/CallRegiXAsync - certificate thumbprint: {clientCert.Certificate?.Thumbprint}");

                RegiXResponse response = await RegiXUtility.CallAsync(client, request);

                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static async Task <RegiXResponse> CallAsync(RegiXEntryPointClient client, ServiceRequestData request)
        {
            Guid callId;
            //string rawResponse;
            ServiceResultData result;

            RawMessage rawRequestMessage  = new RawMessage();
            RawMessage rawResponseMessage = new RawMessage();

            try
            {
                callId = RegiXMessageInspector.BeforeCall();

                if (client == null)
                {
                    client = new RegiXEntryPointClient();
                }
                await client.OpenAsync();

                result = await client.ExecuteSynchronousAsync(request);

                await client.CloseAsync();
            }
            catch (Exception ex)
            {
                client.Abort();
                throw ex;
            }
            finally
            {
                //rawResponse = RegiXMessageInspector.AfterCall(callId);
                RegiXMessageInspector.AfterCallAll(callId, ref rawRequestMessage, ref rawResponseMessage);
            }

            return(new RegiXResponse(result, rawRequestMessage, rawResponseMessage));
        }
Beispiel #3
0
        private RegiXEntryPointClient CreateRegiXEntryPointClient()
        {
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);

            binding.Name = _regixCertificateSettings.BindingName;
            binding.MaxReceivedMessageSize = _regixCertificateSettings.MaxReceivedMessageSize;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

            EndpointAddress address = new EndpointAddress(_regixCertificateSettings.EndpointAddress);

            RegiXEntryPointClient client = new RegiXEntryPointClient(binding, address);

            client.ClientCredentials.ClientCertificate.SetCertificate(
                StoreLocation.LocalMachine,
                StoreName.My,
                X509FindType.FindByThumbprint,
                _regixCertificateSettings.CertificateThumbprint);

            RegiXEndpointBehavior behavior = new RegiXEndpointBehavior();

            client.Endpoint.EndpointBehaviors.Add(behavior);

            return(client);
        }
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(RegiXEntryPointClient.GetEndpointAddress(EndpointConfiguration.WSHttpBinding_IRegiXEntryPoint));
 }
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(RegiXEntryPointClient.GetBindingForEndpoint(EndpointConfiguration.WSHttpBinding_IRegiXEntryPoint));
 }
 public RegiXEntryPointClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(RegiXEntryPointClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
 public RegiXEntryPointClient(EndpointConfiguration endpointConfiguration) :
     base(RegiXEntryPointClient.GetBindingForEndpoint(endpointConfiguration), RegiXEntryPointClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
 public RegiXEntryPointClient() :
     base(RegiXEntryPointClient.GetDefaultBinding(), RegiXEntryPointClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.WSHttpBinding_IRegiXEntryPoint.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }