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

Creating a SOAP Server - 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).

  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



Creating a SOAP server with the native SOAP extension is easier than you think. Although several server-specific methods are provided with the SOAP extension, only three methods are required to create a complete WSDL-enabled server. This section introduces these and other methods, guiding you through the process of creating a functional SOAP server as the section progresses. The section “SOAP Client and Server Interaction” offers a complete working example of the interaction between a WSDL-enabled client and server created using this extension. To illustrate this, the examples in the remainder of this chapter refer to Listing 20-6, which offers a sample WSDL file. Directly following the listing, a few important SOAP configuration directives are introduced that you need to keep in mind when building SOAP services using this extension.

Listing 20-6. A Sample WSDL File (boxing.wsdl)

<?xml version="1.0" ?>
  <definitions name="boxing"
               targetNamespace="http:// www.wjgilmore.com/boxing" 
    xmlns:xsd="http:// www.w3.org/2001/XMLSchema"
    xmlns:soap="http:// schemas.xmlsoap.org/wsdl/soap/"

    <message name="getQuoteRequest">
      <part name="boxer" type="xsd:string" />

    <message name="getQuoteResponse">
      <part name="return" type="xsd:string" />

    <portType name="QuotePortType">
<operation name="getQuote">
        <input message="tns:getQuoteRequest" />
        <output message="tns:getQuoteResponse" /> 

    <binding name="QuoteBinding" type="tns:QuotePortType">
            style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
      <operation name="getQuote">
        <soap:operation soapAction="" />
            <soap:body use="encoded" 

             encodingStyle="http:// schemas.xmlsoap.org/soap/encoding/" /> 
<soap:body use="encoded"
            encodingStyle="http:// schemas.xmlsoap.org/soap/encoding/" /> 

   <service name="boxing">
     <documentation>Returns quote from famous pugilists</documentation>
     <port name="QuotePort" binding="tns:QuoteBinding">
         location="http:// www.wjgilmore.com/boxingserver.php" />

TheSoapServer()constructor instantiates a new instance of theSoapServer class in WSDL or non-WSDL mode. Its prototype looks like this:

object SoapServer->SoapServer(mixed wsdl [, array options])

If you require WSDL mode, you need to assign thewsdl parameter the WSDL file’s location, or else set it toNULL. The optionaloptionsparameter is an array used to set the following options:

actor: Identifies the SOAP server as an actor, defining its URI.

encoding: Sets the character encoding.

soap_version: Determines the supported SOAP version and must be set with the syntax

SOAP_x_y, wherex is an integer specifying the major version number, andy is an integer specifying the corresponding minor version number. For example, SOAP version 1.2 would be assigned asSOAP_1_2.

The following example creates aSoapServer object referencing theboxing.wsdlfile:

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

If the WSDL file resides on another server, you can reference it using a valid URI:

$soapserver = new SoapServer("http://www.example.com/boxing.wsdl");

Next, you need to export at least one function, a task accomplished using theaddFunction()method, introduced next.

Note  If you’re interested in exposing all methods in a class through the SOAP server, use the methodsetClass(), introduced later in this section.



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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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