当我遇到 Soap 连接问题时,我试图捕捉 这是我的服务
namespace AppBundleService;
use AppBundleEntityUsuarios;
use AppBundleEntityRoles;
use DoctrineORMEntityManagerInterface;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentSecurityCoreEncoderEncoderFactoryInterface;
class ADService
{
private $em;
private $encoderFactory;
private $URLService = 'http://XXX.XXX.XXX.XXX?wsdl';
private $soap;
public function __construct (EntityManagerInterface $em, EncoderFactoryInterface $encoderFactory)
{
$this->em = $em;
$this->encoderFactory = $encoderFactory;
try {
$this->soap = new SoapClient($this->URLService, array('trace' => 0, 'exceptions' => true));
}
catch (SoapFault $sf) {
echo "Soapfault";
$this->soap = null;
}
catch (Exception $e) {
echo "Exception";
$this->soap = null;
}
}
但这给我带来了一个错误
肥皂错误:解析 WSDL:无法从 'http://XXX.XXX.XXX.XXX?wsdl' : 无法加载外部 实体 "XXX.XXX.XXX.XXX?wsdl">
如何捕获肥皂连接错误。 提前致谢
这就是我为解决我的问题所做的
$file_headers = @get_headers($this->URLService);
if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
$this->soap = null;
return;
} else {
$this->soap = new SoapClient($this->URLService);
}
如果有人有更好的解决方案,请发布。