Soy algo nuevo en esto de consumir `webservices`, tengo que enviar un archivo a un web service y recibir una respuesta, mi problema es que no he podido generar un `SOAP Header` valido. El web service a consumir es este: https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica/facturaElectronica.wsdl las especificaciones en el documento son que el header debe quedar asi: Ejemplo de petición usando Base64 POST /B2BIntegrationEngine/FacturaElectronica HTTP/1.1 Accept-Encoding: gzip,deflate Content-Type: text/xml;charset=UTF-8 SOAPAction: "" Content-Length: 3342 Host: 192.168.250.65:9080 Connection: Keep-Alive User-Agent: Apache-HttpClient/4.1.1 (java 1.5) <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-html --> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura"> <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:UsernameToken> <wsse:Username>8ac82326-3016-430f-8d69-9efc4bcefd8f</wsse:Username> <wsse:Password>6361b7b5322acb07ced00a35a85a4cc5183da3a42ede0b07f578067a18425a55</wsse:Password> <wsse:NonceEncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">FmbZRkx1jh2A+imgjD2fLQ==</wsse:Nonce> <wsu:Created>2015-10-06T12:00:33.762Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <!-- end snippet --> Pero por mas que trato, lo unico que he podido obtener es esto: <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-html --> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <s:Header> <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <o:UsernameToken u:Id="uuid-c635f931-8274-4d3d-82a1-460a2f04af73-1"> <o:Username>22ffb485-64bc-4619-8a63-340de2dd7eec</o:Username> <o:Password>+eho+ADhrJkwZtKGabXIZOEX/0YVa206TmKnQSwt+qE=</o:Password> </o:UsernameToken> </o:Security> </s:Header> <!-- end snippet --> Esto es lo que estoy haciendo: const string apiUrl = "https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica", apiUserName = "8ac82326-3016-430f-8d69-9efc4bcefd8f"; string apiPassword = "6361b7b5322acb07ced00a35a85a4cc5183da3a42ede0b07f578067a18425a55"; EndpointAddress endpointAddress = new EndpointAddress(new Uri(apiUrl)); SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); securityElement.AllowInsecureTransport = false; securityElement.EnableUnsecuredResponse = true; securityElement.IncludeTimestamp = false; TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8); HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement(); CustomBinding binding = new CustomBinding(securityElement, encodingElement, transportElement); //basic prueba BasicHttpSecurityMode securityMode = new BasicHttpSecurityMode(); BasicHttpBinding binding2 = new BasicHttpBinding(securityMode); // Then assign username and password based on the proxy. For example - //var remoteAddress = new EndpointAddress(""); WSDian.facturaElectronicaPortNameClient service = new WSDian.facturaElectronicaPortNameClient(binding, endpointAddress); //WSDian.facturaElectronicaPortNameClient service = new WSDian.facturaElectronicaPortNameClient(binding2, endpointAddress); service.ClientCredentials.UserName.UserName = apiUserName; service.ClientCredentials.UserName.Password = apiPassword; var Obtnonce = GetNonce(); byte[] archivo = FileToByteArray(@"c:\temp\ws_f0816002834000000000A.zip"); service.Open(); WSDian.EnvioFacturaElectronica enviofactura = new WSDian.EnvioFacturaElectronica(); enviofactura.NIT = "816002834"; enviofactura.InvoiceNumber = "10"; enviofactura.IssueDate = Convert.ToDateTime("2018-01-01 05:00:00"); enviofactura.Document = archivo; //temporal WSDian.EnvioFacturaElectronicaPeticion envioFacturaElectronicaPeticion = new WSDian.EnvioFacturaElectronicaPeticion(); WSDian.EnvioFacturaElectronicaRespuesta envioFacturaElectronicaRespuesta = new WSDian.EnvioFacturaElectronicaRespuesta(); WSDian.AcuseRecibo acuseRecibo = new WSDian.AcuseRecibo(); WSDian.ReceivedInvoice receivedInvoice = new WSDian.ReceivedInvoice(); WSDian.facturaElectronicaPortNameClient facturaElectronicaPortNameClient = new WSDian.facturaElectronicaPortNameClient(); envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1 = enviofactura; var versionSoap = acuseRecibo.GetType(); acuseRecibo = service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1); Pero estoy obteniendo el error: > The security token could not be authenticated or authorized; nested exception is org.apache.ws.security.WSSecurityException: The security token could not be authenticated or authorized No entiendo cómo generar la cabecera SOAP como la solicitan, ¿No debería el `wsdl` generarla de manera automática? Gracias por su ayuda.