如何在 PHP 中进行 SOAP 调用? [英] How to make a SOAP call in PHP?

查看:53
本文介绍了如何在 PHP 中进行 SOAP 调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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

当我尝试实现标头并将 SOAP 调用发送到服务器时,总是收到内部错误"或未知内容编码".我在标题和调用的正确实现方面遇到了一些问题,我需要像代码一样发送.

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.

我用 PHP 得到了什么:

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>

我在 PHP 上有这个

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

推荐答案

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

这篇关于如何在 PHP 中进行 SOAP 调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆