PHP:如何从这个XML做一个SOAP请求?

时间:2017-01-27 15:23:58

标签: php web-services soap soapheader

有人能帮助我吗?

我无法在此Web服务中执行AdvogadoRegular功能。

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:int="https://www5.oab.org.br/integracao/">
   <soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <token xmlns="http://CFOAB.Integracao">xxxxxxxx</token>
      <wsa:To>https://www5.oab.org.br/Integracao/CNA.svc</wsa:To>
   </soap:Header>  
   <soap:Body>
      <int:AdvogadoRegular>
         <!--Optional:-->
         <int:cpf>99999999999</int:cpf>
      </int:AdvogadoRegular>
   </soap:Body>
</soap:Envelope>

我尝试从该代码访问。

// WSDL
$client = new SoapClient('https://www5.oab.org.br/Integracao/CNA.svc?wsdl', $options = array(
                                                                            'soap_version' => SOAP_1_2,
                                                                            'trace'=>1, 
                                                                            'exceptions'=> 0
            ));

// NOME DA FUNÇÃO A SER EXECUTADA
$function = 'AdvogadoRegular';

// PARÂMETROS DA FUNÇÃO A SER EXECUTADA
$arguments= array('AdvogadoRegular' => array( 'cpf'  => '99999999999' ));

// URL DO WEB SERVICE
$options = array('location' => 'https://www5.oab.org.br/Integracao/CNA.svc');


// HEADER
$token = array(
    'token'=> 'xxxxxxxx',
    'wsa:To'=>'https://www5.oab.org.br/Integracao/CNA.svc',

);
$header = new SoapHeader("http://CFOAB.Integracao",'token',$token,false);
$client->__setSoapHeaders($header);



// EXECUTA A FUNÇÃO
$result = $client->__soapCall($function, $arguments, $options);

echo $result;

我认为当我尝试发送标头时会发生错误。请帮帮我......

1 个答案:

答案 0 :(得分:1)

首先我建议你使用WSDL到php生成器,例如PackageGenerator,然后关于你的标题,它似乎是你必须发送的WsSecurity标题,所以你应该尝试使用{{3}项目,简化了添加此类标题的方式