具有 wsdl 自动发现功能的 Zend Soap Server 无法按预期工作

发布于 2024-10-18 11:01:28 字数 2282 浏览 7 评论 0原文

这个问题

我试图在 wsdl 自动发现模式下使用 Zend_Soap_Server 创建一个 Web 服务,但我得到了非常奇怪的效果......这里是代码: server:

<?php
require_once('Zend/Soap/AutoDiscover.php');
require_once('Zend/Soap/Server.php');
require_once('Zend/Soap/Wsdl.php');
require_once('library/SoapActions.php');
$wsdl = new Zend_Soap_Autodiscover();
$wsdl->setClass('SoapActions');
if (isset($_GET['wsdl'])) {
$wsdl->handle();
    } else {
    $server = new Zend_Soap_Server('http://localhost:8083/server.php?wsdl');
    $server->setClass('SoapActions');
    $server->setEncoding('ISO-8859-1');
    $server->handle();
    }

SoapActions class:

class SoapActions {

/**
 * Test function
 * 
 * @param String $a
 * @param String $b
 * @return String
 */
 public function test1($a, $b) {
    return "you passed me ".$a." ".$b;
 }

 /**
 * Test function 2
 * 
 * @param String $a
 * @param String $b
 * @return String
 */
 public function test2($a, $b) {
    return "you passed me ".$a." ".$b;
 }

}

我尝试使用 Zend_Soap_Client 类来使用函数 test1 和 test2,这里的代码:

require_once('Zend/Soap/Client.php');
    $client = new Zend_Soap_Client("http://localhost:8083/server.php?wsdl");

    try {
        echo $client->test2("foo","bar"); //this works!
    } catch (Exception $e) {
        echo $e;
    }

    try {
        echo $client->test1("foo","bar"); //this doesn't work!
    } catch (Exception $e) {
        echo $e;
    }

我无法理解,因为 test2 函数按预期工作, test1 函数返回以下异常:

SoapFault 异常:[Sender] 函数 (“test1”) 不是有效的方法 这项服务在 /usr/local/zend/share/ZendFramework/library/Zend/Soap/Client.php:1121 堆栈跟踪: 0 /usr/local/zend/share/ZendFramework/library/Zend/Soap/Client.php(1121): SoapClient->__soapCall('test1', Array, 空、空、数组) 1 /usr/local/zend/apache2/htdocs/webservice/client.php(6): Zend_Soap_Client->__call('test1', 大批) 2 /usr/local/zend/apache2/htdocs/webservice/client.php(6): Zend_Soap_Client->test1('foo', 'bar') 3 {主要}

我尝试反转函数名称...结果令人难以置信,仅适用于 test2!我快疯了,似乎在服务器端的某个地方保存了函数名称......

有人可以帮助我吗?

Duplicate of this question

I'm trying to create a web service with Zend_Soap_Server in wsdl autodiscovery mode, but I obtain very strange effects... here the code:
server:

<?php
require_once('Zend/Soap/AutoDiscover.php');
require_once('Zend/Soap/Server.php');
require_once('Zend/Soap/Wsdl.php');
require_once('library/SoapActions.php');
$wsdl = new Zend_Soap_Autodiscover();
$wsdl->setClass('SoapActions');
if (isset($_GET['wsdl'])) {
$wsdl->handle();
    } else {
    $server = new Zend_Soap_Server('http://localhost:8083/server.php?wsdl');
    $server->setClass('SoapActions');
    $server->setEncoding('ISO-8859-1');
    $server->handle();
    }

SoapActions class:

class SoapActions {

/**
 * Test function
 * 
 * @param String $a
 * @param String $b
 * @return String
 */
 public function test1($a, $b) {
    return "you passed me ".$a." ".$b;
 }

 /**
 * Test function 2
 * 
 * @param String $a
 * @param String $b
 * @return String
 */
 public function test2($a, $b) {
    return "you passed me ".$a." ".$b;
 }

}

I tried to use the function test1 and test2 using the Zend_Soap_Client class, here the code:

require_once('Zend/Soap/Client.php');
    $client = new Zend_Soap_Client("http://localhost:8083/server.php?wsdl");

    try {
        echo $client->test2("foo","bar"); //this works!
    } catch (Exception $e) {
        echo $e;
    }

    try {
        echo $client->test1("foo","bar"); //this doesn't work!
    } catch (Exception $e) {
        echo $e;
    }

I cannot understand because the test2 function works as expected, the test1 function return the following exception:

SoapFault exception: [Sender] Function
("test1") is not a valid method for
this service in
/usr/local/zend/share/ZendFramework/library/Zend/Soap/Client.php:1121
Stack trace:
0 /usr/local/zend/share/ZendFramework/library/Zend/Soap/Client.php(1121):
SoapClient->__soapCall('test1', Array,
NULL, NULL, Array)
1 /usr/local/zend/apache2/htdocs/webservice/client.php(6):
Zend_Soap_Client->__call('test1',
Array)
2 /usr/local/zend/apache2/htdocs/webservice/client.php(6):
Zend_Soap_Client->test1('foo', 'bar')
3 {main}

I tried to invert the functions name... the result is incredible, works only test2! I'm getting crazy, it seems that somewhere on server side it save the function name...

Can someone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城之時有危險 2024-10-25 11:01:28

解决了!问题出在 php.ini 文件中的这个设置:

soap.wsdl_cache_enabled=1

我将其设置为 0,现在它工作正常!

SOLVED! The problem was this setting in the php.ini file:

soap.wsdl_cache_enabled=1

I set this to 0 and now it works fine!

把梦留给海 2024-10-25 11:01:28

如果您不想更改 php.ini:

// WSDL_CACHE_NONE;     /* 0 Pas de cache */
// WSDL_CACHE_DISK;     /* 1 Sur le disque supprimer le fichier pour le réinitialiser */
// WSDL_CACHE_MEMORY;   /* 2 En mémoire => redémarrer Apache pour le réinitialiser */
// WSDL_CACHE_BOTH;     /* 3 En mémoire et sur le disque */

$options = array();
$options['cache_wsdl'] = WSDL_CACHE_NONE;
$client = new Zend_Soap_Client("http://localhost:8083/server.php?wsdl", $options);

If you don't want change your php.ini:

// WSDL_CACHE_NONE;     /* 0 Pas de cache */
// WSDL_CACHE_DISK;     /* 1 Sur le disque supprimer le fichier pour le réinitialiser */
// WSDL_CACHE_MEMORY;   /* 2 En mémoire => redémarrer Apache pour le réinitialiser */
// WSDL_CACHE_BOTH;     /* 3 En mémoire et sur le disque */

$options = array();
$options['cache_wsdl'] = WSDL_CACHE_NONE;
$client = new Zend_Soap_Client("http://localhost:8083/server.php?wsdl", $options);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文