public SoapClient(Uri endpointUri, X509Certificate2 certificate, SignAlgorithm signAlgorithm = SignAlgorithm.Sha256) { HttpClient = new SoapHttpClient(endpointUri); Certificate = certificate; SignAlgorithm = signAlgorithm; XmlManipulator = new XmlManipulator(); }
public async Task <TOut> SendAsync <TIn, TOut>(TIn messageBodyObject, string operation) where TIn : class, new() where TOut : class, new() { var ns = new XmlSerializerNamespaces(); ns.Add("", "http://DescargaMasivaTerceros.gob.mx"); var messageBodyXmlElement = XmlManipulator.Serialize(messageBodyObject, ns); var mesasgeBodyXmlString = messageBodyXmlElement.OuterXml; Logger?.Info("Created XML document from DTOs.", new { XmlString = mesasgeBodyXmlString }); XmlMessageSerialized?.Invoke(this, new XmlMessageSerializedEventArgs(messageBodyXmlElement, "Autenticando")); var soapMessage = new SoapMessage(new SoapMessagePart(messageBodyXmlElement)); var xmlDocument = Certificate == null?soapMessage.GetXmlDocument() : soapMessage.GetSignedXmlDocument(Certificate, SignAlgorithm); var xml = xmlDocument.OuterXml; Logger?.Debug("Created signed XML.", new { SoapString = xml }); var response = await HttpClient.SendAsync(xml, operation).ConfigureAwait(false); Logger?.Debug("Received RAW response from SAT servers.", new { HttpResponseBody = response }); var soapBody = GetSoapBody(response); return(XmlManipulator.Deserialize <TOut>(soapBody)); }
public async Task <TOut> SendAsync <TIn, TOut>(TIn messageBodyObject, string operation) where TIn : class, new() where TOut : class, new() { var messageBodyXmlElement = XmlManipulator.Serialize(messageBodyObject); var mesasgeBodyXmlString = messageBodyXmlElement.OuterXml; Logger?.Debug("Created XML document from DTOs.", new { XmlString = mesasgeBodyXmlString }); XmlMessageSerialized?.Invoke(this, new XmlMessageSerializedEventArgs(messageBodyXmlElement, (messageBodyObject as SendRevenueXmlMessage)?.Data.BillNumber)); var soapMessage = new SoapMessage(new SoapMessagePart(messageBodyXmlElement)); var xmlDocument = Certificate == null?soapMessage.GetXmlDocument() : soapMessage.GetSignedXmlDocument(Certificate, SignAlgorithm); var xml = xmlDocument.OuterXml; Logger?.Debug("Created signed XML.", new { SoapString = xml }); var response = await HttpClient.SendAsync(xml, operation); Logger?.Debug("Received RAW response from EET servers.", new { HttpResponseBody = response }); var soapBody = GetSoapBody(response); return(XmlManipulator.Deserialize <TOut>(soapBody)); }
public SoapClient(Uri endpointUri, Certificate certificate, TimeSpan httpTimeout, SignAlgorithm signAlgorithm = SignAlgorithm.Sha256, EetLogger logger = null) { HttpClient = new SoapHttpClient(endpointUri, httpTimeout, logger); Certificate = certificate; SignAlgorithm = signAlgorithm; XmlManipulator = new XmlManipulator(); Logger = logger; HttpClient.HttpRequestFinished += (sender, args) => HttpRequestFinished?.Invoke(this, args); }
public void InitGUI(ref XmlDocument doc) { _log.WriteLn("In maps InitGUI"); IUIManager uIManager = Repository.Instance.GetManager <IUIManager>(); StringBuilder xmlStr = new StringBuilder(); xmlStr.Append(@"<AccordionSection expanded=""0"" name=""Maps""> <AccordionSectionHeader> <AccordionSectionHeaderIcon /> <Text>Maps</Text> </AccordionSectionHeader> <AccordionSectionContent> <VerticalScrollView> <VerticalLayout> "); DirectoryInfo di = new DirectoryInfo(_rootPath + "/maps"); List <FileInfo> fileList = new List <FileInfo>(); FileSystemUtils.VisitFileTree(di, null, null, (FileInfo fi) => { if (Path.GetExtension(fi.Name) != ".meta") { fileList.Add(fi); } }); foreach (FileInfo fi in fileList) { xmlStr.Append(@"<Text onClick=""SendParamEvent(MAPBUTTONEVT,"); xmlStr.Append(fi.FullName); xmlStr.Append(@")"">"); xmlStr.Append(Path.GetFileNameWithoutExtension(fi.Name)); xmlStr.Append("</Text>\n"); } _log.WriteLn(xmlStr.ToString()); xmlStr.Append(@" </VerticalLayout> </VerticalScrollView> </AccordionSectionContent> </AccordionSection>"); XmlManipulator manip = new XmlManipulator(doc.OuterXml); manip.AddStringToNodeID("AccordianX", xmlStr.ToString()); doc.LoadXml(manip.Text); //_log.WriteLn(doc.OuterXml); uIManager.AddUIEventHandler("MAPBUTTONEVT", ButtonCB); }
public async Task <TOut> SendAsync <TIn, TOut>(TIn messageBodyObject, string operation) where TIn : class, new() where TOut : class, new() { var messageBodyXmlElement = XmlManipulator.Serialize(messageBodyObject).DocumentElement; var soapMessage = new SoapMessage(new SoapMessagePart(messageBodyXmlElement)); var xmlDocument = soapMessage.GetXmlDocument(); var xml = xmlDocument.OuterXml; var httpRequest = GetHttpRequest(operation, xml); var response = await HttpClient(httpRequest); var soapBody = GetSoapBody(response.Content.Value); return(XmlManipulator.Deserialize <TOut>(soapBody)); }
private static Dto.ManageInvoiceRequest CreateManageInvoicesRequest <T>( TechnicalUser user, SoftwareIdentification software, ExchangeToken token, Dto.ManageInvoiceOperationType operation, ISequence <T> invoices, Func <T, Dto.InvoiceData> invoiceDataGetter) { var operations = invoices.Values.Select(item => { var invoiceData = invoiceDataGetter(item.Value); var invoiceDataBytes = Encoding.UTF8.GetBytes(XmlManipulator.Serialize(invoiceData)); return(new Dto.InvoiceOperationType { index = item.Index, invoiceData = invoiceDataBytes, invoiceOperation = operation, electronicInvoiceHash = invoiceData.completenessIndicator.Match( t => new Dto.CryptoType { cryptoType = RequestEncryptionAlgorithm, Value = Sha512.GetSha3Hash(Convert.ToBase64String(invoiceDataBytes)) }, f => null ) }); }); var invoiceHashes = operations.Select(t => Sha512.GetSha3Hash($"{t.invoiceOperation}{Convert.ToBase64String(t.invoiceData)}")); var invoiceSignatureData = string.Join("", invoiceHashes); var request = CreateRequest <Dto.ManageInvoiceRequest>(user, software, invoiceSignatureData); request.exchangeToken = Encoding.UTF8.GetString(token.Value); request.invoiceOperations = new Dto.InvoiceOperationListType { compressedContent = false, invoiceOperation = operations.ToArray() }; return(request); }
private static Dto.ManageInvoiceRequest CreateManageInvoicesRequest <T>(TechnicalUser user, SoftwareIdentification software, ExchangeToken token, Dto.ManageInvoiceOperationType operation, ISequentialEnumerable <T> invoices, Func <T, Dto.InvoiceData> mapper) { var operations = invoices.Select(item => new Dto.InvoiceOperationType { index = item.Index, invoiceData = Encoding.UTF8.GetBytes(XmlManipulator.Serialize(mapper(item.Item))), invoiceOperation = operation }); var invoiceHashes = operations.Select(t => Sha512.GetSha3Hash($"{t.invoiceOperation}{Convert.ToBase64String(t.invoiceData)}")); var invoiceSignatureData = string.Join("", invoiceHashes); var request = CreateRequest <Dto.ManageInvoiceRequest>(user, software, invoiceSignatureData); request.exchangeToken = Encoding.UTF8.GetString(token.Value); request.invoiceOperations = new Dto.InvoiceOperationListType { compressedContent = false, invoiceOperation = operations.ToArray() }; return(request); }
public void OutboundRequestSerializationWorks() { // Arrange var invoicesDocModel = BuildInvoicesDocModel(); var xmlDocument = XmlManipulator.Serialize(invoicesDocModel); xmlDocument.Schemas.Add(InvoicesDoc.Namespace, GetPath("Data/Schemas/InvoicesDoc.xsd")); xmlDocument.Schemas.Add(IncomeClassification.Namespace, GetPath("Data/Schemas/IncomeClassification.xsd")); xmlDocument.Schemas.Add(ExpenseClassification.Namespace, GetPath("Data/Schemas/ExpensesClassificaton.xsd")); bool hasErrors = false; ValidationEventHandler eventHandler = new ValidationEventHandler((o, e) => { hasErrors = true; }); // Act xmlDocument.Validate(eventHandler); // Assert Assert.False(hasErrors); }