简体   繁体   中英

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)

Class With Function: (Metodo.php)

class Teste {


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

}

Server: (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)

<?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(). 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.

In 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). I can't remember off the top of my head if HTTP_HOST does or not.

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. (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). The easiest way to do this is to remove any files that start with 'wsdl' from your /tmp/ folder (or equivalent on your system). 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. There are also some 'trace/debug' settings for the SOAP client. 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.
  • non standard port, not sure why but might be related

Have you tried with the a browser to access the WSDL? Does it resolve?

freenodes' #zftalk channel (IRC) can be a good resource as well. Please post back here if you do find an answer there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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