Guest User

Untitled

a guest
Aug 24th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. const string apiUrl = "https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica",
  2. apiUserName = "8ac82326-3016-430f-8d69-9efc4bcefd8f";
  3.  
  4. string apiPassword = "6361b7b5322acb07ced00a35a85a4cc5183da3a42ede0b07f578067a18425a55";
  5.  
  6. EndpointAddress endpointAddress = new EndpointAddress(new Uri(apiUrl));
  7.  
  8. SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
  9. securityElement.AllowInsecureTransport = false;
  10. securityElement.EnableUnsecuredResponse = true;
  11. securityElement.IncludeTimestamp = false;
  12.  
  13. TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
  14. HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement();
  15.  
  16. CustomBinding binding = new CustomBinding(securityElement, encodingElement, transportElement);
  17.  
  18. //basic prueba
  19. BasicHttpSecurityMode securityMode = new BasicHttpSecurityMode();
  20. BasicHttpBinding binding2 = new BasicHttpBinding(securityMode);
  21.  
  22. // Then assign username and password based on the proxy. For example -
  23. //var remoteAddress = new EndpointAddress("");
  24. WSDian.facturaElectronicaPortNameClient service = new WSDian.facturaElectronicaPortNameClient(binding, endpointAddress);
  25. //WSDian.facturaElectronicaPortNameClient service = new WSDian.facturaElectronicaPortNameClient(binding2, endpointAddress);
  26. service.ClientCredentials.UserName.UserName = apiUserName;
  27. service.ClientCredentials.UserName.Password = apiPassword;
  28. var Obtnonce = GetNonce();
  29. byte[] archivo = FileToByteArray(@"c:tempws_f0816002834000000000A.zip");
  30.  
  31. service.Open();
  32.  
  33. WSDian.EnvioFacturaElectronica enviofactura = new WSDian.EnvioFacturaElectronica();
  34.  
  35. enviofactura.NIT = "816002834";
  36. enviofactura.InvoiceNumber = "10";
  37. enviofactura.IssueDate = Convert.ToDateTime("2018-01-01 05:00:00");
  38. enviofactura.Document = archivo;
  39.  
  40. //temporal
  41.  
  42. WSDian.EnvioFacturaElectronicaPeticion envioFacturaElectronicaPeticion = new WSDian.EnvioFacturaElectronicaPeticion();
  43. WSDian.EnvioFacturaElectronicaRespuesta envioFacturaElectronicaRespuesta = new WSDian.EnvioFacturaElectronicaRespuesta();
  44. WSDian.AcuseRecibo acuseRecibo = new WSDian.AcuseRecibo();
  45. WSDian.ReceivedInvoice receivedInvoice = new WSDian.ReceivedInvoice();
  46. WSDian.facturaElectronicaPortNameClient facturaElectronicaPortNameClient = new WSDian.facturaElectronicaPortNameClient();
  47.  
  48. envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1 = enviofactura;
  49. var versionSoap = acuseRecibo.GetType();
  50. acuseRecibo = service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1);
Add Comment
Please, Sign In to add comment