Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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 Soap客户端或Zend_Soap_客户端不返回任何内容_Php_Zend Framework_Soap_Zend Soap - Fatal编程技术网

PHP Soap客户端或Zend_Soap_客户端不返回任何内容

PHP Soap客户端或Zend_Soap_客户端不返回任何内容,php,zend-framework,soap,zend-soap,Php,Zend Framework,Soap,Zend Soap,我正在尝试构建一个简单的Web服务,并且在一个情况下运行。 我不知道自己做错了什么,所以无法获取soap服务器返回的值 我的indexController中有一个Zend_Soap_服务器和一个Zend_Soap_客户端: class IndexController extends Zend_Controller_Action { public function init() { $this->getHelper('viewRenderer')->

我正在尝试构建一个简单的Web服务,并且在一个情况下运行。 我不知道自己做错了什么,所以无法获取soap服务器返回的值

我的indexController中有一个Zend_Soap_服务器和一个Zend_Soap_客户端:

class IndexController 
extends Zend_Controller_Action
{

    public function init()
    {
        $this->getHelper('viewRenderer')->setNoRender(true);
        Zend_loader::loadFile( APPLICATION_PATH . '/../library/Web/Service.php' );
    }

    public function indexAction() {}

    public function serverAction()
    {

        if( isset( $_GET['wdsl'] ) ) {
            $server = new Zend_Soap_AutoDiscover();
            $server->setClass('Web_Service');
            $server->handle();
        } else {
            $options = array(
                'soap_version' => SOAP_1_1 ,
                'uri' => 'http://webservices.localhost/index/server?wdsl=1'
            );
            $server = new Zend_Soap_Server(null, $options);
            $server->setClass('Web_Service');
            $server->handle();
        }
    }

    public function testAction()
    {
        $client = new Zend_Soap_Client(
            'http://webservices.localhost/index/server?wdsl'
        );

        print( $client->getMessage() ) ;
    }

}
一个非常简单的服务类传递给soap服务器:

class Web_Service
{

    public function getMessage()
    {
        return 'ok';
    }

}
当我请求Soap服务器的URL时,它会返回我猜应该返回的内容:

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://webservices.misterprint.com.br/index/server" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Web_Service" targetNamespace="http://webservices.misterprint.com.br/index/server">
<types>
<xsd:schema targetNamespace="http://webservices.misterprint.com.br/index/server"/>
</types>
<portType name="Web_ServicePort">
<operation name="getMessage">
<documentation>getMessage</documentation>
<input message="tns:getMessageIn"/>
</operation>
</portType>
<binding name="Web_ServiceBinding" type="tns:Web_ServicePort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getMessage">
<soap:operation soapAction="http://webservices.misterprint.com.br/index/server#getMessage"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://webservices.misterprint.com.br/index/server"/>
</input>
</operation>
</binding>
<service name="Web_ServiceService">
<port name="Web_ServicePort" binding="tns:Web_ServiceBinding">
<soap:address location="http://webservices.misterprint.com.br/index/server"/>
</port>
</service>
<message name="getMessageIn"/>
</definitions>
我不知道我做错了什么


提前谢谢

您好,有几件事您可能想先检查一下,尽管我很感激您可能已经知道/已经做了

在开发SOAP服务时,除非您更改了任何默认设置,否则WSDL可能会被缓存

您可能希望将其添加到相关环境设置下的application.ini中,例如正在开发中

phpSettings.soap.wsdl_cache_enabled = 0
这意味着您的WSDL将不会被缓存,您可以排除这方面的任何问题——尽管在说您的WSDL看起来确实可以看到您尝试使用的方法

此外,当使用ZF自动生成WSDL时,您将希望向方法添加基本注释,以便ZF WSDL生成器可以提取这些注释,例如添加任何@param和@return信息。像这样:

 /**     
  * @return string
  */
 public function getMessage()
 {
     return 'ok';
 }
因此,完成后,尝试使用服务器方法做一些不同的事情…尝试

public function serverAction()
{
    $baseUrl = 'http://webservices.localhost/index/server';

    if( isset( $_GET['wdsl'] ) ) {
        $strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
        $server = new Zend_Soap_AutoDiscover($strategy);
        $server->setUri($baseUrl);
        $server->setClass('Web_Service');
        $server->handle();
    } else {            
        $server = new Zend_Soap_Server($baseUrl . '?wsdl');
        $server->setClass('Web_Service');
        $server->handle();
    }
}

只是想澄清一下,如果你添加了我建议的注释,那么一定要确保WSDL缓存已经关闭,否则Zend_Soap_客户端可能会使用旧版本,你将无法继续前进……因此@Dave Clark,我遵循了你的提示,但我仍然无法打印出“ok”字符串。不用担心,刚刚添加了一个快速代码示例供您尝试…现在可以了吗?现在可以了!非常感谢!顺便说一下,你很有礼貌!
public function serverAction()
{
    $baseUrl = 'http://webservices.localhost/index/server';

    if( isset( $_GET['wdsl'] ) ) {
        $strategy = new Zend_Soap_Wsdl_Strategy_AnyType();
        $server = new Zend_Soap_AutoDiscover($strategy);
        $server->setUri($baseUrl);
        $server->setClass('Web_Service');
        $server->handle();
    } else {            
        $server = new Zend_Soap_Server($baseUrl . '?wsdl');
        $server->setClass('Web_Service');
        $server->handle();
    }
}