Estoy consumiendo un Servicio web para enviar un archivo
https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica/facturaElectronica.wsdl
Pero en el debug me devuelve la siguiente excepción:
System.ServiceModel.Security.MessageSecurityException: 'Error de comprobación de seguridad de mensajes.' InvalidOperationException: Signaturas de token auxiliar no esperadas.
System.ServiceModel.Security.MessageSecurityException: Error de comprobación de seguridad de mensajes. ---> System.InvalidOperationException: Signaturas de token auxiliar no esperadas. en System.ServiceModel.Security.ReceiveSecurityHeader.ProcessSupportingSignature(SignedXml signedXml, Boolean isFromDecryptedSource) en System.ServiceModel.Security.ReceiveSecurityHeader.ExecuteFullPass(XmlDictionaryReader reader) en System.ServiceModel.Security.StrictModeSecurityHeaderElementInferenceEngine.ExecuteProcessingPasses(ReceiveSecurityHeader securityHeader, XmlDictionaryReader reader) en System.ServiceModel.Security.ReceiveSecurityHeader.Process(TimeSpan timeout, ChannelBinding channelBinding, ExtendedProtectionPolicy extendedProtectionPolicy) en System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessageCore(Message& message, TimeSpan timeout) en System.ServiceModel.Security.TransportSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout)
Para realizar el envio del archivo realizo lo siguiente:
public string envioFacturaElectronicaMTOM()
{
const string apiUrl = "https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica";
byte[] archivo = FileToByteArray(@"c:\temp\ws_f0890900162000000dad3.zip");
EndpointAddress endpointAddress = new EndpointAddress(new Uri(apiUrl));
var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.AllowInsecureTransport = false;
securityElement.EnableUnsecuredResponse = true;
securityElement.IncludeTimestamp = false;
var encodingElement = new MtomMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
var transportElement = new HttpsTransportBindingElement();
var binding = new CustomBinding(securityElement, encodingElement, transportElement);
facturaElectronicaPortNameClient Service = new facturaElectronicaPortNameClient(binding, endpointAddress);
Service.ClientCredentials.UserName.UserName = "MiSoftwareID";
Service.ClientCredentials.UserName.Password = "MiPasswordEnSHA256";
WSDian.EnvioFacturaElectronica enviofactura = new WSDian.EnvioFacturaElectronica();
enviofactura.NIT = "MiNIT";
enviofactura.InvoiceNumber = "124063277";
enviofactura.IssueDate = Convert.ToDateTime("2018-05-28 20:17:19");
enviofactura.Document = Convert.FromBase64String(Convert.ToBase64String(archivo));
EnvioFacturaElectronicaPeticion envioFacturaElectronicaPeticion = new EnvioFacturaElectronicaPeticion();
envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1 = enviofactura;
AcuseRecibo acuseRecibo = new AcuseRecibo();
acuseRecibo = Service.EnvioFacturaElectronica(envioFacturaElectronicaPeticion.EnvioFacturaElectronicaPeticion1);
return acuseRecibo.Comments.ToString();
}
En la respuesta de esta pregunta esta como estoy consumiendo el servicio web de manera completa, no lo escribo aquí ya que es extenso: c# Consumir web service facturacion electronica
Cuando hago el seguimiento con fiddler, veo lo siguiente en el Request:
POST https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:1a31b7a4-bb88-4bd7-aa99-6bfca75980a0+id=1";start-info="text/xml"
SOAPAction: ""
Host: facturaelectronica.dian.gov.co
Content-Length: 9191
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
--uuid:1a31b7a4-bb88-4bd7-aa99-6bfca75980a0+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
<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>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPonyxdQ1ypqsgAAAAAInUwvSubfkWtkosj7GNjAU+JUra/JWZAnJwNPpSrhZUACQAA</VsDebuggerCausalityData>
<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-dceca3e0-7764-477b-aac4-3e5ad3303a9f-1">
<o:Username><!--Removed--></o:Username>
<o:Password><!--Removed--></o:Password>
</o:UsernameToken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EnvioFacturaElectronicaPeticion xmlns="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura">
<NIT><!--Removed--></NIT>
<InvoiceNumber>124063277</InvoiceNumber>
<IssueDate>2018-05-28T20:17:19</IssueDate>
<Document><xop:Include href="cid:http://tempuri.org/1/636719021136260437" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></Document>
</EnvioFacturaElectronicaPeticion>
</s:Body>
</s:Envelope>
--uuid:1a31b7a4-bb88-4bd7-aa99-6bfca75980a0+id=1
Content-ID: <http://tempuri.org/1/636719021136260437>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream
PK x M h .c face_f0890900161000000faf3.xml |ۖ Ⱥ O Ⱦ 9 39
--uuid:1a31b7a4-bb88-4bd7-aa99-6bfca75980a0+id=1--
Y el response que recibo es el siguiente:
HTTP/1.1 200 OK
Date: Fri, 07 Sep 2018 12:28:33 GMT
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: Multipart/Related; start-info="text/xml"; type="application/xop+xml"; boundary="----=_Part_504669_2132088323.1536323314599"
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Set-Cookie: TS0133d910=01ca0e1ef64130a10e8ff09c341631cb87ffd0b88debb404b553072ef7b937149aeae0ee703398a88c3adec21a15c42b7a1d9ebafc; Path=/
Content-Length: 3256
------=_Part_504669_2132088323.1536323314599
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" SOAP-ENV:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-478012">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="SOAP-ENV"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#id-478011">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList=""/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>gPOXTVuXDw2ktXu3Fiyjoz35JwY=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>e7AOmryll5EXw3euAOlO2CwL+N3wpR+QHz8Zmlz+hBFZ7kmQ9QXkupO+MUkDrnHu/MsOZr7Q0j60heMbM4u3yIiTRPE0HsEOV1BQ/+v0LX+XSGo1EiHlcYbEo8Yn+aHFmR4z81TV8TycRXMBUoyJXl2Y/yLjFPH8TptpKLagEOYgcJQ340Cw7rVBfG+tuVwU388F/MDiv/vRhIjpHViSHSP8C7xO5NZvNoGsg5f66ATzkwkB4wmeAmHud3Mbuj7Vdq3Sw==</ds:SignatureValue>
<ds:KeyInfo Id="KI-0ACB9EF7167DC955151536323314584358508">
<wsse:SecurityTokenReference wsu:Id="STR-0ACB9EF7167DC955151536323314584358509">
<ds:X509Data>
<ds:X509IssuerSerial>
<ds:X509IssuerName>CN=AC SUB CERTICAMARA,O=CERTICAMARA S.A,OU=NIT 830084433-7,C=CO,ST=DISTRITO CAPITAL,L=BOGOTA,STREET=www.certicamara.com</ds:X509IssuerName>
<ds:X509SerialNumber>91436926122049919406185072624124</ds:X509SerialNumber>
</ds:X509IssuerSerial>
</ds:X509Data>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</ds:Signature>
<wsu:Timestamp wsu:Id="TS-478010">
<wsu:Created>2018-09-07T12:28:34.584Z</wsu:Created>
<wsu:Expires>2018-09-07T12:33:34.584Z</wsu:Expires>
</wsu:Timestamp>
<wsse11:SignatureConfirmation xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" wsu:Id="SC-478009"/>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-478011">
<ns2:EnvioFacturaElectronicaRespuesta xmlns:ns2="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura" xmlns:ns3="http://www.dian.gov.co/servicios/facturaelectronica/ConsultaDocumentos" xmlns:ns4="http://www.dian.gov.co/servicios/facturaelectronica/VersionDespliegue">
<ns2:Version>Componente DIAN</ns2:Version>
<ns2:ReceivedDateTime>2018-09-07T07:28:34.392-05:00</ns2:ReceivedDateTime>
<ns2:ResponseDateTime>2018-09-07T07:28:34.583-05:00</ns2:ResponseDateTime>
<ns2:Response>200</ns2:Response>
<ns2:Comments>Ejemplar recibido exitosamente pasará a verificación.</ns2:Comments>
</ns2:EnvioFacturaElectronicaRespuesta>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
------=_Part_504669_2132088323.1536323314599--
--------------------------------------------------
caf
------=_Part_67971_1574199767.1536252188646
¿No sé qué podrá estar pasando o como debo recibir la respuesta para que el C# no me arroje la excepción?
Gracias.