With the poor documentation that exists regarding the implementation with the WebService yesterday and today I exhausted my resources to investigate the error that I am receiving, and assuming that the same DIAN (Tax entity in Colombia) does not answer the phones (I was hung up for 2 hours and nothing ...) and much less the emails because I put here the question if someone can help me and in the same way it helps any programmer who is in the same situation.
When submitting the invoice I receive an error stating " JBWEB000120: The request sent by the client was syntactically incorrect ".
I pass the complete Request and Respose:
POST /habilitacion/B2BIntegrationEngine/FacturaElectronica HTTP/1.0
Host: facturaelectronica.dian.gov.co
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: ""
Content-Length: 28319
<soap-env:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura" xmlns:ns2323="http://tempuri.org">
<soap-env:header>
<wsse:security soapenv:mustunderstand="1" 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">
<wsse:usernametoken wsu:id="UsernameToken-2">
<wsse:username>d8xxx-exxx-4xxx-axxx-aaxxxx</wsse:username>
<wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile1.0#PasswordText">a8bxxxxHash265xxxxxx99</wsse:password>
<wsse:nonce encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security1.0#Base64Binary">bW9uxxxxxxxxxxxxxxUyNg==</wsse:nonce>
<wsu:created>2019-01-23T16:08:39-06:00</wsu:created>
</wsse:usernametoken>
</wsse:security>
</soap-env:header>
<soap-env:body>
<rep:enviofacturaelectronicapeticion>
<rep:nit>700xxxx</rep:nit>
<rep:invoicenumber>980000000</rep:invoicenumber>
<rep:issuedate>2019-01-23T16:08:39-06:00</rep:issuedate>
<rep:document>UEsDBBQA.....AuMS4yNzA3</rep:document>
</rep:enviofacturaelectronicapeticion>
</soap-env:body>
</soap-env:envelope>
And the response:
<title>JBoss Web/7.4.8.Final-redhat-4 - JBWEB000064: Error report</title>
<h1>JBWEB000065: HTTP Status 400 - </h1>
<p><b>JBWEB000309: type</b> JBWEB000067: Status report</p>
<p><b>JBWEB000068: message</b> <u></u></p>
<p><b>JBWEB000069: description</b> <u>JBWEB000120: The request sent by the client was syntactically incorrect.</u></p>
---- Edited 2019/01/30, 15:38. I made some changes to the NuSOAP library since when sending the information it passed everything to lowercase (strtolower()), so I removed the use of the strtolower() function in everything that consisted of sending , and the error now changed, I He says:
HTTP/1.0 302 Found Location: https://facturaelectronica.dian.gov.co/habilitacion/B2BIntegrationEngine/FacturaElectronica Server: BigIP Connection: close Content-Length: 0
The problem persists :(....
---- Edited 2019/01/31, 13:15. After trying with SOAPUI I realized that the main problem is the NuSOAP libraries, so due to the time I have wasted on this and contemplating that it seems more feasible to make the code in Socket by putting together the frame to verify if there are problems with the WebService of the DIAN I have chosen to assemble it by hand.
I coded it and just realized that for some unknown reason NuSOAP does other things that throw the error mentioned at the beginning. Right now I'm talking to the DIAN because I'm sending the frame manually as required by the WebService and it keeps giving me the error:
Client 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
And the code that I have so far for the tests by hand is:
<?php
public function createXML() {
# crea el XML SOAP
}
public funciton getXML() {
# retorna el xml con $xml->saveXML();
}
public function sendToDIAN($wsUrl) {
$this->createXML();
$s= curl_init();
curl_setopt($s, CURLOPT_URL, $wsUrl);
curl_setopt($s, CURLOPT_HTTPHEADER, array("User-Agent: moneyBox", "Content-Type: text/xml; charset=UTF-8", "SOAPAction:", "Content-Length: ". strlen($this->getXML())) );
curl_setopt($s, CURLOPT_HEADER, 1 );
curl_setopt($s, CURLOPT_POST, 1);
curl_setopt($s, CURLOPT_POSTFIELDS, $this->getXML());
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_VERBOSE, TRUE);
curl_setopt($s, CURLINFO_HEADER_OUT, true);
$resp= curl_exec($s);
$rq= curl_getinfo($s);
echo "<br>WS: ". $wsUrl;
echo "<br>XML:<br>";
print_r($this->getXML());
echo "<br>Request:<br>";
print_r($rq["request_header"]);
echo "<br><br>Response:<br>";
print_r($resp);
?>
The request is:
POST /habilitacion/B2BIntegrationEngine/FacturaElectronica/facturaElectronica.wsdl HTTP/1.1
Host: facturaelectronica.dian.gov.co
Accept: */*
User-Agent: PHP
Content-Type: text/xml; charset=UTF-8
Content-Length: 28198
Expect: 100-continue
<!--?xml version="1.0" encoding="UTF-8"?-->
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://www.dian.gov.co/servicios/facturaelectronica/ReportarFactura">
<soapenv:header>
<wsse:security soapenv:mustunderstand="1" 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">
<wsse:usernametoken wsu:id="UsernameToken-2">
<wsse:username>d8xxx-exxx-4xx0-axx2-aa4xxxxxda</wsse:username>
<wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile1.0#PasswordText">2fb7a2xxxxxxxxe6de4a</wsse:password>
<wsse:nonce encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security1.0#Base64Binary">bW9xxxxxMTU1MA==</wsse:nonce>
<wsu:created>2019-01-31T14:05:50.000Z</wsu:created>
</wsse:usernametoken>
</wsse:security>
</soapenv:header>
<soapenv:body>
<rep:enviofacturaelectronicapeticion>
<rep:nit>700xxxx7</rep:nit>
<rep:invoicenumber>980000000</rep:invoicenumber>
<rep:issuedate>2019-01-31T14:05:50</rep:issuedate>
<rep:document>UEsDBB....jEuMjcwNw==</rep:document>
</rep:enviofacturaelectronicapeticion>
</soapenv:body>
</soapenv:envelope>
The Response is:
HTTP/1.1 100 Continue
HTTP/1.1 500 Internal Server Error
Date: Thu, 31 Jan 2019 19:05:51 GMT
Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
SOAPAction: ""
Content-Type: text/xml;charset=utf-8
Content-Length: 443
X-Cnection: close
Set-Cookie: TS0133d910=01ca0e1ef6f0097a1348704194309a4e9b294fed9c0bcca644e4ae8558c221f7f76b430cee909654460964cd09e1ac5affe8cd8d04; Path=/
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:header></soap-env:header>
<soap-env:body>
<soap-env:fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">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</faultstring>
</soap-env:fault>
</soap-env:body>
</soap-env:envelope>
After several editions of the initial publication, finally the solution was that in order to comply with the requirements of the DIAN Tax entity for the assembly of the SOAP Request "sooo personalized" I chose not to use the NuSOAP library nor SOAPClient(), since any different or additional value that was appended to the labels was throwing me error messages without a specific description for their resolution and the investment of time in the debugging and solution was delaying me a lot, for which I had to put together the XML of the Request in a "manual" using DOMDocument and making the connection by Socket (cURL).
Another additional tip that is IMPORTANT TO MENTION is that, after making the SOAP connection "by hand", the error was more "accessible" since it mentioned "Authentication error", and for this particular case after exhausting the options of : Verify that the Software ID, the SOAP Url and the Password were correct, I had to choose to delete the Software ID from the DIAN portal and generate it again, this solved the Authentication Error part . It was possibly due to changes in the DIAN system that affects Software IDs in Test mode , but that was the 2nd solution.
Here is an idea of the code that I finally generated for the manual part:
The Request: