Home arrow PHP arrow Page 3 - SOAP Servers and Web Services

Adding a Server Function - PHP

In this conclusion to a five-part article series on Web Services, you'll learn how to create a SOAP server, add server functions, and more. This article is excerpted from chapter 20 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

TABLE OF CONTENTS:
  1. SOAP Servers and Web Services
  2. Creating a SOAP Server
  3. Adding a Server Function
  4. Adding Class Methods
  5. SOAP Client and Server Interaction
By: Apress Publishing
Rating: starstarstarstarstar / 3
August 10, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

You can make a function available to clients by exporting it using the addFunction() method. In the WSDL file, there is only one function to implement, getQuote(). It takes $boxer as a lone parameter and returns a string. Letís create this function and expose it to connecting clients:

<?php
   
function getQuote($boxer) {
       
if ($boxer == "Tyson") {
           
$quote = "My main objective is to be professional
                     
but to kill him. (2002)";
       
} elseif ($boxer == "Ali") {
           
$quote = "I am the greatest. (1962)";
       
} elseif ($boxer == "Foreman") {
           
$quote = "Generally when there's a lot of smoke,
                     
there's just a whole lot more smoke. (1995)";
       
} else {
           
$quote = "Sorry, $boxer was not found.";
       
}
       
return $quote;
    }

    $soapserver = new SoapServer("boxing.wsdl");

    $soapserver->addFunction("getQuote");
?>

When two or more functions are defined in the WSDL file, you can choose which ones are to be exported by passing them in as an array, like so:

$soapserver->addFunction(array("getQuote","someOtherFunction");

Alternatively, if you would like to export all functions defined in the scope of the SOAP server, you can pass in the constantSOAP_FUNCTIONS_ALL, like so:

$soapserver->addFunction(array(SOAP_FUNCTIONS_ALL);

Itís important to understand that exporting the functions is not all that you need to do to produce a valid SOAP server. You also need to properly process incoming SOAP requests, a task handled for you via the methodhandle(). This method is introduced next.



 
 
>>> More PHP Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: