Search code examples
phpsoapwsdl

How to make a SOAP call in PHP?


I have to make a SOAP Call on a Axis2 Server with parameters, but I have a lot of problems, I done this on SOAPUI and works fine.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
    <Seguridad>
     <usuario>0000000000</usuario>
      <password>9FDB5D2R4J62755C7DA205S52D8G4H36D4CRCB94978BC40DDD2D4220CB63FE7E</password>
      <fechaSistema>02/01/2015</fechaSistema>
     </Seguridad>
   </soapenv:Header>
   <soapenv:Body>
      <ws:enviaCONVOL xmlns:ws="http://ws.convol/">
         <!--Optional:-->
         <arg0>2014-12-31</arg0>
         <!--Optional:-->
         <arg1>11:48:46</arg1>
         <!--Optional:-->
         <arg2>ZmUxMzc3ZDmyYTc3YTAyZjM2YT8lZDc4MzgwOTZhY2Y0YTM1MDg3Wg==</arg2>
         <!--Optional:-->
         <arg3>ZmUxMzc3ZDmyYTc3YTAyZjM2YT8lZDc4MzgwOTZhY2Y0YTM1MDg3Wg==</arg3>
      </ws:enviaCONVOL>
   </soapenv:Body>
</soapenv:Envelope>

I need do this with soap in PHP and MTOM, and the arg2 is a CID from a zip file.

When I tried to implement the header and send the SOAP call to the server always receive "Internal Error " or "Unknown Content-Encoding". I am having some problems with the headers and the correct implementation of the call, I need to send like the code.

what i get with PHP:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.convol/"><SOAP-ENV:Body><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                    <soapenv:Header>
                            <Seguridad>
                         <usuario>0000105847</usuario>
                          <password>9FDBDE265822755C7DA2058053B61580736ECB94978BC40DDD2D4220CB63FE7E</password>
                          <fechaSistema>02/01/2015</fechaSistema>
                         </Seguridad>
                       </soapenv:Header>
                       <soapenv:Body>
                          <ws:enviaCONVOL xmlns:ws="http://ws.convol/">
                             <!--Optional:-->
                             <arg0>2014-12-31</arg0>
                             <!--Optional:-->
                             <arg1>11:48:46</arg1>
                             <!--Optional:-->
                             <arg2>ZmUxMzc3ZDQyYTc3YTAyZjM2YThlZDc4MzgwOTZhY2Y0YTM1MDg3Ng==</arg2>
                             <!--Optional:-->
                             <arg3>ZmUxMzc3ZDQyYTc3YTAyZjM2YThlZDc4MzgwOTZhY2Y0YTM1MDg3Ng==</arg3>
                          </ws:enviaCONVOL>
                       </soapenv:Body>
                    </soapenv:Envelope></SOAP-ENV:Body></SOAP-ENV:Envelope>

I had this on PHP

try{    
    $client=new SoapClient('https://www.convolmiscelaneapruebas.pemex.com/ServiciosCVWEB/ServicioEnviaCONVOLService/ServicioEnviaCONVOLService.wsdl',array( 'trace' => 1, 'exceptions' => 0 ));

    $header = '<SOAP-ENV:Header>
                            <Seguridad>
                         <usuario>0000000000</usuario>
                          <password>9FDBDE265822755C50dHD5D33B61580736ECB94978BC40DDD2D4220CB63FE7E</password>
                          <fechaSistema>02/01/2015</fechaSistema>
                         </Seguridad>
                       </SOAP-ENV:Header>';

    $xml = '<ns1:enviaCONVOL>
                             <!--Optional:-->
                             <arg0>2014-12-31</arg0>
                             <!--Optional:-->
                             <arg1>11:48:46</arg1>
                             <!--Optional:-->
                             <arg2>ZmUxMzc3ZDQyYTc3YTAyZddd5IMKYThlZDc4MzgwOTZhY2Y0YTM1MDg3Ng==</arg2>
                             <!--Optional:-->
                             <arg3>ZmUxMzc3ZDQyYTdnHD90D3185D4MzgwOTZhY2Y0YTM1MDg3Ng==</arg3>
                          </ns1:enviaCONVOL>
                       ';
    $args = array(new SoapVar($xml, XSD_ANYXML));    
    $res  = $client->__soapCall('enviaCONVOL', $args);

    echo "<hr>Last Request<br>";
    echo "<pre>", htmlspecialchars($client->__getLastRequest()), "</pre>";


    print_r($res);
}catch (SoapFault $fault){
        echo "SOAPFault: ".$fault->faultcode." - ".$fault->faultstring.' - '.$fault->getMessage();
}

I can´t put the Header in the right place...


Solution

  • I used NuSoap

    $wsdl = "https://www.convolmiscelaneapruebas.pemex.com/ServiciosCVWEB/ServicioEnviaCONVOLService/ServicioEnviaCONVOLService.wsdl";
    $client = new nusoap_client($wsdl,TRUE);
    $header = 
    "<Seguridad>
      <usuario>0000000000</usuario>
      <password>4e671bf08913d677c56359262117c8e67a5507b165f727288a487040bf2a1780</password>
      <fechaSistema>02/01/2015</fechaSistema>
    </Seguridad>";
    $operation = array('arg0' => '2014-12-31', 
            'arg1' => '11:48:46', 
            'arg2'=>'12095866ae89b7dbcd44640189c57e185918192739040eb52ba5b==',
            'arg3'=>'ZmU5866axMzc3ZDQyJmdAyZjM2YThlZDb7dbcd446401YTM1Mg3Ng=='
            );
    $client->setHeaders($header);
    $res = $client->call('enviaCONVOL',$operation);