Handle SOAP requests

Next we must handle any requests to the web service. This involves filling in the “else” block from the previous listing.

To achieve this, we use the Zend_Soap_Server class. Just like Zend_Soap_AutoDiscover, it needs to the know the name of the class that holds the web service methods.

Additionally, when we instantiate Zend_Soap_Server we need to pass to it the URL of the web service. This is so the server knows which methods to handle, as well its data types (Zend_Soap_Server doesn’t do any auto-discovery of the class you pass to it with setClass()).

You can either hard-code the URL of the WSDL file, or you can auto-generate its location as in Listing 4.

Note: This URL auto-generator is somewhat simple. You may need to account for different port names or for using HTTPS.

Listing 4 shows how to instantiate the Zend_Soap_Server class, set the WSDL, set the PHP class and then handle the request.

Listing 4 Handle SOAP requests (webservice.php)
    if ($_SERVER['QUERY_STRING'] == 'wsdl') {
        $auto = new Zend_Soap_AutoDiscover();
    else {
        $wsdl = sprintf(
        $soapServer = new Zend_Soap_Server($wsdl);

That’s all there is to it. The next step is to actually consume the web service, as covered in the next section.

From phpriot.com


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s