当我遇到 Soap 连接问题时,我正在尝试捕捉这是我的服务
namespace AppBundle\Service;
use AppBundle\Entity\Usuarios;
use AppBundle\Entity\Roles;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
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;
}
}
但这给我一个错误
SOAP 错误:解析 WSDL:无法从“ http://XXX.XXX.XXX.XXX?wsdl ”加载:无法加载外部实体“XXX.XXX.XXX.XXX?wsdl”
如何捕获soap 连接错误。提前致谢
这是我为解决我的问题所做的
$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);
}
如果有人有更好的解决方案,请发布。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句