Symfony 3捕获Soap连接错误

时间:2017-07-14 17:23:46

标签: php web-services symfony soap

当我遇到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-ERROR:解析WSDL:无法加载   'http://XXX.XXX.XXX.XXX?wsdl':无法加载外部   实体“XXX.XXX.XXX.XXX?wsdl”

如何捕获soap连接错误。 提前致谢

1 个答案:

答案 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);
    }

如果有人有更好的解决方案,请发布。