Question

I am trying to build a simple webservice, and am running accross a situation. I don't know what I am doing wrong so that I can't grab the values returned by soap server.

I have a Zend_Soap_Server and a Zend_Soap_Client inside my indexController:

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() ) ;
    }

}

And a very simple Service class passed to the soap server:

class Web_Service
{

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

}

When I request the URL for my Soap Server it returns what I guess is supposed to be returned:

<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>

But when I access the test for the client, it prints nothing!

If I change the getMessage method's name to getMessages for instance, Zend throws me the exception:

Message: Function ("getMessages") is not a valid method for this service

I don't know what I am doing wrong.

Thanks in advance!

Was it helpful?

Solution

Hi couple of things you might want to check first although I appreciate you may already know this/have done it.

While developing a SOAP service, unless you've changed any default settings you're WSDL may be being cached.

You may want to add this to your application.ini under the relevant environment setting eg under development.

phpSettings.soap.wsdl_cache_enabled = 0

That means your WSDL won't be cached and you can rule out any issues on that front - although in saying that your WSDL does seem to be see the method you're trying to use.

Also when auto generating a WSDL with ZF you will want to add basic comments to the method so they can be picked up by the ZF WSDL generator eg adding any @param and @return info. Like this:

 /**     
  * @return string
  */
 public function getMessage()
 {
     return 'ok';
 }

So with that done try doing something different with your server method....try

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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top