简体   繁体   English

Web服务-PHP Zend(空白页-无错误)

[英]Web Service - PHP Zend ( Blank Page - No Errors )

I made a simple version of my code. 我做了一个简单的代码版本。 It gives no errors, but it simply doesn't work. 它没有错误,但是根本不起作用。 (I have Soap enabled for PHP) (我为PHP启用了Soap)

Class With Function: (Metodo.php) 具有功能的类:(Metodo.php)

class Teste {


    /*
    * @return string
    */
    function SayHello() {
        return "Hello, WORLD";
    }

}

Server: (Server.php) 服务器: (Server.php)

<?php

require_once('Metodo.php');

if($_SERVER['QUERY_STRING'] == "wsdl") {

    try {

        require_once('Zend/Soap/AutoDiscover.php');
        $wsdl = new Zend_Soap_AutoDiscover();
        $wsdl->setClass('Teste');
        $wsdl->handle();

    }catch(exception $e) {
        echo $e->getMessage();
    }

} else {

    $wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);

    require_once('Zend/Soap/Server.php');
    $server = new SoapServer($wsdl_url);
    $server->setClass('Teste');
    $server->handle();

}

?>

Client: (Client.php) 客户端: (Client.php)

<?php

    require_once('Zend/Soap/Client.php');
    $wsdl_url = "http://localhost:8090/WebService/Server.php?wsdl";
    $client = new Zend_Soap_Client($wsdl_url);

    try {
        echo $client->SayHello();
        echo ":)";
    } catch (SoapFault $e) {
        echo $e->getMessage();
    }

    ?>

It just prints ":)", no errors, but it won't call the method SayHello(). 它只打印“ :)”,没有错误,但是不会调用方法SayHello()。 If anyone would PLEASE help me, I would be so thankful. 如果有人能帮助我,我将非常感激。 Really. 真。 Thank you so much. 非常感谢。

A few things: 一些东西:

$server = new SoapServer($wsdl_url);

should be: 应该:

$server = new Zend_Soap_Server($wsdl_url);

it may work without, but since you required in the Zend Soap Server class on the line before, you may as well use it. 它可能无法运行,但是由于您之前在Zend Soap Server类中需要,因此最好使用它。

In Server.php: 在Server.php中:

$wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);

make sure that this URL includes the right port (as you are using port 8090). 确保此URL包含正确的端口(与使用端口8090相同)。 I can't remember off the top of my head if HTTP_HOST does or not. 如果不使用HTTP_HOST,我就不记得了。

And then most importantly, in your class: 然后最重要的是,在您的课堂上:

/*
* @return string
*/
function SayHello() {
    return "Hello, WORLD";
}

should be: 应该:

/**
* @return string
*/
function SayHello() {
    return "Hello, WORLD";
}

note the extra * at the start of the comment. 注意注释开头的多余的*。 The auto discovery classes work using PHPDoc blocks, which must start with /** in order to be valid. 自动发现类使用PHPDoc块工作,该块必须以/ **开头才能生效。 (Easy to miss!) (容易错过!)

If it still doesn't work after these changes, make absolutely sure that PHP has not cached your bad WSDL file (PHP caches WSDL files by default). 如果在完成这些更改后它仍然不起作用,请绝对确保PHP尚未缓存不良的WSDL文件(默认情况下,PHP会缓存WSDL文件)。 The easiest way to do this is to remove any files that start with 'wsdl' from your /tmp/ folder (or equivalent on your system). 最简单的方法是从/ tmp /文件夹(或系统上的等效文件)中删除所有以'wsdl'开头的文件。 After making these changes I got the right output using your code. 进行这些更改后,我使用您的代码获得了正确的输出。

There should be an error being logged someplace. 在某个地方记录错误。 Check the server and PHP logs. 检查服务器和PHP日志。 There are also some 'trace/debug' settings for the SOAP client. SOAP客户端还有一些“跟踪/调试”设置。 You might get more info back on last call/response with those enabled. 如果启用了这些功能,您可能会获得有关上一次呼叫/响应的更多信息。

With out more info here are some observations: 在没有更多信息的情况下,有一些观察结果:

  • non standard function name. 非标准函数名称。 In ZF camelCase is the norm. 在ZF中,camelCase是规范。
  • non standard port, not sure why but might be related 非标准端口,不确定为什么但可能相关

Have you tried with the a browser to access the WSDL? 您是否尝试过使用浏览器访问WSDL? Does it resolve? 它解决了吗?

freenodes' #zftalk channel (IRC) can be a good resource as well. freenodes的#zftalk频道(IRC)也是很好的资源。 Please post back here if you do find an answer there. 如果您在此处找到答案,请发回此处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM