Reputation: 300
English is not my native language so please be patient.
I need an specific envelope to consume the WebService, because the Server administrator is a non cooperative person. Right now I'm a little confused because I do not know where to start.
I need to report the state of some letters and bills, was able to use PHP to make a script which search in a MySQL database the information to report trought webService.
The administrator instead of sending me an IP address with the "wsdl" configuration to make a PHP Soap Client, send an example text file (xml type) to make an envelope. Using SoapUI was able to get an answer (an error answer, but still an answer) but I'm trying to do an automatic report (using Cron), but I don't know how to make an envelope from an XML to make the SoapClient to report.
The example envelope is the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esb.comfenalcovalle.com.co/">
<soapenv:Header/>
<soapenv:Body>
<ws:requestMessageOut>
<ws:header>
<ws:invokerDateTime>2017-05-05</ws:invokerDateTime>
<ws:moduleId>ACTUALIZA_CORRESPONDENCIA</ws:moduleId>
<ws:systemId></ws:systemId>
<ws:messageId>ACTUALIZA_CORRESPONDENCIA|123456789</ws:messageId>
<ws:logginData>
<ws:sourceSystemId></ws:sourceSystemId>
<ws:destinationSystemId></ws:destinationSystemId>
</ws:logginData>
<ws:destination>
<ws:namespace>http://co/com/comfenalcovalle/esb/ws/BPSirapActualizaCorrespondencia</ws:namespace>
<ws:name>BPSirapActualizaCorrespondencia</ws:name>
<ws:operation>execute</ws:operation>
</ws:destination>
<ws:securityCredential>
<ws:userName></ws:userName>
<ws:userToken></ws:userToken>
</ws:securityCredential>
<ws:classification>
<!--Zero or more repetitions:-->
<ws:classification></ws:classification>
</ws:classification>
</ws:header>
<ws:body>
<ws:request>
<BPSirapActualizaCorrespondenciaProcessRequest>
<pividdocu>1075000000010907</pividdocu>
<pinidesdo>25</pinidesdo>
<pinidmoed></pinidmoed>
<pivdireccion>CR 34-10 229</pivdireccion>
<pivcodigoLeyMuni>76001</pivcodigoLeyMuni>
<pivcodigoLeyDpto>76</pivcodigoLeyDpto>
<pivnumeroGuia>574127725</pivnumeroGuia>
<pivnumeroRemision>0102205-12</pivnumeroRemision>
<pivguia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ca92BpKYAB+wy0apXcKwkh+VkGm7jsbUVP5tlDUUtJXj7wTE16HZJ1GlQ/Ysa824ttmzMx41qAXrdJTlGiYZEiKeu0asRruD9n7HTZDIlaebMFYWUm+7YXEyQOPJxjRG1ZHkYnnairKJB3YxmL8LN5xhSW3Dk6cMcGOV9RkA6lYpkA2LJFJZEya3rhMZTmmWCmxTy8t5p2yLBMLoIgMwBr/hayI7kYSz5Mruam6dusuUYZMtu0cy3nZ6XyQOq4lWw07/HKtJMYr0aNNZMv9724q+WVuvKn3/pymmdzhqYlw5CAkmwjVSXwM0nmLomyB+c2NvqnLnRzmFg1jbvKkJoU/x6Z3r4fCzdf/H3o6Invf0WAxjgkMf7S8Nlfy8bhYJ5FH1VB2SpFPFe5Ga8+X9mymiBXs3DTrop8jagQ3jz5Qxd8tO2eRf8KlmeOhWijhXBlSoWAuq2FLMBJuvHpRl9azQO2maNft11Fv22SoGJQSHJjw0sX4oEe0iegoaYI9dssLACroudBXr8vs9dv18DYjo6+EUw73ZwseflEO2zky2jja8vMtJhxx9jLDohu5caDRGUPaSNpLmlClAhIGWFdID3FBuyf/pH410TE/yB/CzAAZIXaj6vGZXwAAAAASUVORK5CYII=</pivguiaDigitalizada>
</BPSirapActualizaCorrespondenciaProcessRequest>
</ws:request>
</ws:body>
</ws:requestMessageOut>
</soapenv:Body>
</soapenv:Envelope>
If you copy/paste this code to SoapUI and set "endpoint" to: https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter ... You'll get the error answer I was talking about.
Some links I was looking trought my search for an answer:
how to generate a soap request in php from this xml?
https://www.wackylabs.net/2004/07/creating-a-web-service-and-wsdl-using-nusoap/
how to create soap xml request in php
PHP SoapClient: multiple complex types are overwritten in soapcall
how to generate XML with soap envelope and body tag using php
------------------> Update May 18
Thanks to Alex Blex for his answer, using his point to make the XML as a "String" could be able to use a workaround to consume the WebService, Instead of configure the Client just use a "null".
$location_URL = 'https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter';
$action_URL = "https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter";
$client = new SoapClient(null, array(
'location' => $location_URL,
'uri' => "https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter",
'trace' => 1,
));
$return = $client->__doRequest($xmlString,$location_URL,$action_URL,1);
Sadly the $return is also an String, instead an object or an XML, so is very dificult to obtain the report and store in a database.
When I use the method proposed by Alex Blex, doesn't receive anything, this is a minor modification to his code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter');
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xmlstring );
$result = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
$resArr = array();
$resArr = json_decode($result);
$xml = simplexml_load_string($result);
echo "<pre>"; print_r($result); echo "</pre>";
echo "<pre>"; print_r($info); echo "</pre>";
echo "<pre>"; print_r($resArr); echo "</pre>";
echo "<pre>"; print_r($errors); echo "</pre>";
curl_close($ch);
I'm already working the Client, but any correction or new method could be implemented ASAP.
Upvotes: 2
Views: 2764
Reputation: 37108
You can do it low level with cURL.
If you POST the xml to the API like
curl --request POST \
--url https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter \
--data '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esb.comfenalcovalle.com.co/"> .... </soapenv:Envelope>'
You actually get a successful response
....
<NS1:responseMessageOut xmlns:NS1="http://ws.esb.comfenalcovalle.com.co/">
<NS1:header>
<NS1:invokerDateTime>2017-05-05</NS1:invokerDateTime>
<NS1:moduleId>ACTUALIZA_CORRESPONDENCIA</NS1:moduleId>
<NS1:systemId></NS1:systemId>
<NS1:messageId>ACTUALIZA_CORRESPONDENCIA|123456789</NS1:messageId>
<NS1:logginData>
<NS1:sourceSystemId></NS1:sourceSystemId>
<NS1:destinationSystemId></NS1:destinationSystemId>
</NS1:logginData>
<NS1:destination>
<NS1:namespace>http://co/com/comfenalcovalle/esb/ws/BPSirapActualizaCorrespondencia</NS1:namespace>
<NS1:name>BPSirapActualizaCorrespondencia</NS1:name>
<NS1:operation>execute</NS1:operation>
</NS1:destination>
<NS1:responseStatus>
<NS1:statusCode>SUCESS</NS1:statusCode>
</NS1:responseStatus>
</NS1:header>
<NS1:body>
<NS1:response>
<BPSirapActualizaCorres
....
In php it should be something like
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter');
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $theXML );
$result = curl_exec($ch);
curl_close($ch);
The response in $result
can be parsed with DOMXml or SimpleXML.
Upvotes: 3