internal async Task <DeliveryResult> SendMessageToMailBoxOperator(SealedDelivery SealedDelivery, X509Certificate2 x509Certificate2, string endpointAdress) { logger.LogTrace(string.Format("SE.GOV.MM.Integration.Infrastructure.MessageHandler: entering SendMessageToMailBoxOperator")); var binding = new BasicHttpBinding() { Security = new BasicHttpSecurity() { Transport = new HttpTransportSecurity() { ClientCredentialType = HttpClientCredentialType.Certificate }, Mode = BasicHttpSecurityMode.Transport } }; try { var client = new ServicePortv3Client(binding, new EndpointAddress(endpointAdress)); client.ClientCredentials.ClientCertificate.Certificate = x509Certificate2; logger.LogTrace(string.Format("SE.GOV.MM.Integration.Infrastructure.MessageHandler: Sending message to MailBoxOperator")); var response = await client.deliverSecureAsync(SealedDelivery); logger.LogTrace(string.Format("SE.GOV.MM.Integration.Infrastructure.MessageHandler: leaving SendMessageToMailBoxOperator")); return(response.@return); } catch (Exception ce) { logger.LogError(ce, ce.Message); throw ce; } }
/// <summary> /// Sends a SealedDelivery object to the recipient mailbox using the certificate configured in web.config. /// </summary> /// <param name="delivery"></param> /// <param name="mailbox"></param> /// <param name="SSLCertificate_FindByThumbprint"></param> /// <param name="requestId"></param> /// <returns></returns> public DeliveryResult SendMessageToMailboxOperatorV3(SealedDelivery2 delivery, Mailbox mailbox, string SSLCertificate_FindByThumbprint, Guid requestId) { LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: incoming SendMessageToMailboxOperatorV3 with RequestId: {0}", requestId)); DeliveryResult result = null; var binding = new BasicHttpBinding() { Security = new BasicHttpSecurity() { Transport = new HttpTransportSecurity() { ClientCredentialType = HttpClientCredentialType.Certificate }, Mode = BasicHttpSecurityMode.Transport } }; try { //MG Relight ändrade FindByThumbprint X509FindType.FindBySubjectName var client = new ServicePortv3Client(binding, new EndpointAddress(mailbox.ServiceAdress)); client.Endpoint.Behaviors.Add(new FaultFormatingBehavior()); client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, SSLCertificate_FindByThumbprint); result = client.deliverSecure(delivery); } catch (FaultException fe) { string errorMessage = string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: SOAPFAULT SendMessageToMailboxOperatorV3 with RequestId: {0}", requestId); LogManager.Log(new Log.Log() { EventId = EventId.CommunicationExceptionWithService, Exception = fe, Level = Level.Error, Message = errorMessage }); throw fe; } catch (Exception e) { string errorMessage = string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: EXCEPTION in SendMessageToMailboxV3 with RequestId: {0}", requestId); LogManager.Log(new Log.Log() { EventId = EventId.CommunicationExceptionWithService, Exception = e, Level = Level.Error, Message = errorMessage }); throw e; } LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: leaving SendMessageToMailboxV3 with RequestId: {0}", requestId)); return(result); }