PHP SoapClient:无法打开流:HTTP请求失败

时间:2017-01-04 11:54:47

标签: php soap zend-framework

我会尽力解释我的问题。

1 - 我用PHP创建了Soap服务器(ZF1项目:)

class WebServiceAction Extends Zend_Controller_Action
{

  public function soapAction()
  {
    $this->_helper->layout()->disableLayout();
    $this->getHelper('viewRenderer')->setNoRender(true);
    if (isset($_GET['wsdl'])) {
      $this->wsdl();
    }
    $this->handleSOAP();
  }

  protected function handleSOAP()
  {
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer('http://localhost/myproject/webservice/soap?wsdl');
    $server->setClass('Webservice_Model_MyClass');

    $server->handle();
    exit;
  }

  protected function wsdl()
  {
    // set up WSDL auto-discovery
    $wsdl = new Zend_Soap_AutoDiscover();
    // attach SOAP service class
    $wsdl->setClass('Webservice_Model_MyClass');
    $wsdl->handle();
    exit;
  }
}

2 - Web服务类:

class Webservice_Model_MyClass
{
    /**
   * Testing the server
   *
   * @return  string
   */
  public function testing() {
    return 'It works bla bla!!!';
  }
}

3 - 我用PHP创建了Soap客户端(ZF2项目:)

try{
    $soapClient = new \SoapClient(
        'http://localhost/myproject/webservice/soap?wsdl', 
        array(
            'cache_wsdl' => WSDL_CACHE_NONE,
            'soap_version' => SOAP_1_2,
            'trace' =>1
        )
    );

    $result = $soapClient->testing();
    var_dump($result); exit();
}catch(\Exception $e){
    echo $e->getMessage();
}

我收到错误:

Warning: SoapClient::SoapClient(http://localhost/myproject/webservice/soap?wsdl): 
failed to open stream: HTTP request failed! in ....

Warning: SoapClient::SoapClient(): I/O warning : 
failed to load external entity "http://localhost/myproject/webservice/soap?wsdl" in ....

如果我在浏览器地址栏中输入http://localhost/myproject/webservice/soap?wsdl,我会收到wsdl

0 个答案:

没有答案
相关问题