PHP SoapClient 请求响应



嗨,我必须构建一个 soap 客户端来请求: https://api.edu.gov.pt/services/e360/listStudentCodes?wsdl 这是我的代码:

$Username="********";
$PAssword="********";
$anolectivo=2017;
$CodEscola=123456;
$Codes="https://api.edu.gov.pt/services/e360/listStudentCodes?wsdl";
$options = array(
'login' => $Username,
'password' => $password,
'exceptions' => false,
'trace' => 1
,'stream_context' => stream_context_create(array('ssl'=>array('verify_peer'=>false,'verify_peer_name'=>false, 'allow_self_signed' => true)))
);  
try{
$client = new SoapClient($Codes,$options);   
$result = $client->__soapCall("ListarCodigosAlunos",array('AnoLetivo' => $anolectivo,'CodigoAgrupamento' => $CodEscola,'CodigoEscola' => $CodEscola),$options);
if (is_soap_fault($result)) {
trigger_error("Error SOAP: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}else print_r($result);   
} catch (Exception $e) { 
echo "<h2>Exception Error!</h2>"; 
echo $e->getMessage(); 
} 

但我得到的只是:

致命错误:SOAP-ERROR:解析 WSDL:第 34 行的 E:\xampp\htdocs\SOAP\test.php 中未知所需的 WSDL 扩展"http://www.w3.org/2006/05/addressing/wsdl">


我设法下到

SoapFault Object
(
[message:protected] => Wrong Version
[string:Exception:private] => 
[code:protected] => 0
[file:protected] => E:xampphtdocsSOAPe360T2.php
[line:protected] => 46
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => E:xampphtdocsSOAPe360T2.php
[line] => 46
[function] => __soapCall
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => ListarCodigosAlunos
[1] => Array
(
[AnoLetivo] => 2018
[CodigoAgrupamento] => 400324
[CodigoEscola] => 400324
)

您有两个选择:

自己下载 WSDL 文件,对其进行编辑以将wsdl:required="true"更改为wsdl:required="false",然后将 SOAP 客户端配置为使用本地 WSDL。

或者使用外部库,例如以下理解 WSDL 扩展的库之一:

https://github.com/robrichards/wse-php

https://github.com/coopTilleuls/wse-php

最新更新