如何在 PHP 中进行 SOAP 调用?

How to make a SOAP call in PHP?

我必须使用参数在 Axis2 服务器上进行 SOAP 调用,但我遇到了很多问题,我在 SOAPUI 上完成了这个并且工作正常。

<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>

我需要在 PHP 和 MTOM 中使用 soap 来执行此操作,arg2 是来自 zip 文件的 CID。

当我尝试实现 header 并将 SOAP 调用发送到服务器时,总是收到 "Internal Error " 或 "Unknown Content-Encoding"。我在 headers 和调用的正确实现方面遇到了一些问题,我需要像代码一样发送。

我用 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>

我在 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();
}

我无法将 Header 放在正确的位置...

我用的是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);