Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用ZF2创建SOAP服务?_Php_Web Services_Soap_Wsdl_Zend Framework2 - Fatal编程技术网

Php 如何使用ZF2创建SOAP服务?

Php 如何使用ZF2创建SOAP服务?,php,web-services,soap,wsdl,zend-framework2,Php,Web Services,Soap,Wsdl,Zend Framework2,我的代码有什么问题?如何为我的数学课创建SOAP服务? 请注意,我并没有提到Math.php的名称空间,因为若我这样做了,那个么我得到的Math类在浏览器上不存在消息。 在不提及Math类的名称空间的情况下,如何在indexAction中创建Math对象。 请指导我如何为数学类创建第一个wsdl 文件夹结构 单元 -肥皂 --控制器 --->IndexController.php --服务 --->Math.php IndexController.php Math.php 结果XML 关于Mat

我的代码有什么问题?如何为我的数学课创建SOAP服务? 请注意,我并没有提到Math.php的名称空间,因为若我这样做了,那个么我得到的Math类在浏览器上不存在消息。 在不提及Math类的名称空间的情况下,如何在indexAction中创建Math对象。 请指导我如何为数学类创建第一个wsdl

文件夹结构 单元 -肥皂 --控制器 --->IndexController.php --服务 --->Math.php

IndexController.php

Math.php

结果XML


关于Math.php中编写的名称空间,您是对的

在IndexController.php中试试这个-

include_once __DIR__ . '/../Services/Math.php';

class IndexController extends AbstractActionController {

    private $_URI = "http://zf2.services/soap";

    public function indexAction() {
        $autodiscover = new \Zend\Soap\AutoDiscover();
        $autodiscover->setClass('Math')
                     ->setBindingStyle(array('style' => 'document'))
                     ->setUri($this->_URI);
        header('Content-type: application/xml');
        echo $autodiscover->toXml();
        exit();
    }
}

我已经试过了,效果很好。

我以前的方法有什么问题?我如何从soapclient使用这个wsdl?你能提供一些关于ZF2 SOAP的参考链接吗?这个链接足够了——对于详细的实现,你必须在专门为它编写的google博客上找到。至少我是这样学会ZF2的。祝你好运
//namespace Soap\Services;
    class Math
    {
       /**
        * Method
        * @return string
        */
       public function greeting()
       {
         return 'Hello world';
       }
    }
<SOAP-ENV ..>
 <SOAP-ENV:Body>
  <SOAP-ENV:Fault>
   <faultcode>sender</faultcode>
   <faultstring>Invalid XML</faultstring>
  </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
</SOAP-ENV>
include_once __DIR__ . '/../Services/Math.php';

class IndexController extends AbstractActionController {

    private $_URI = "http://zf2.services/soap";

    public function indexAction() {
        $autodiscover = new \Zend\Soap\AutoDiscover();
        $autodiscover->setClass('Math')
                     ->setBindingStyle(array('style' => 'document'))
                     ->setUri($this->_URI);
        header('Content-type: application/xml');
        echo $autodiscover->toXml();
        exit();
    }
}