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-ERROR:解析WSDL:无法加载 'http://XXX.XXX.XXX.XXX?wsdl':无法加载外部 实体“XXX.XXX.XXX.XXX?wsdl”
如何捕获soap连接错误。 提前致谢
答案 0 :(得分:0)
这是我为解决问题而做的
$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);
}
如果有人有更好的解决方案,请发布。