Home arrow Zend arrow Page 4 - PHP SOAP Extension

A First SOAP Server - Zend

This article describes the new SOAP extension for PHP. It is intended for PHP developers who want to write their own Web Services servers, or use SOAP to access existing ones. It assumes some familiarity with Web Services, SOAP, and WSDL (Web Services Description Language).

TABLE OF CONTENTS:
  1. PHP SOAP Extension
  2. A First SOAP Client
  3. Using WSDL
  4. A First SOAP Server
  5. Creating the Server
  6. Example 6
  7. Example 8 (client5.php)
  8. Other Implementations of SOAP for PHP
By: Zend
Rating: starstarstarstarstar / 23
March 17, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Let’s try to write our own SOAP Web service that will do the same as the XMethods “Delayed Stock Quote” service.

The first task is to create a WSDL document describing our service in a format that client requests will understand. This requires minor modifications to the original document taken from the Xmethods site, so we’ll start by taking a close look at that file.

The message section defines two messages.  The first is getQuoteRequest, which is a request to relay the getQuote message and takes one string parameter called symbol. The other is getQuoteResponse, which is a response to the getQuote message, containing one float value, named Result.

The portType section defines one operation, getQuote, which describes which of the messages listed in the message section will be used to transmit the request and response.

The binding section defines how the messages must be transmitted and encoded. Here it tells us that we will be sending an RPC request using SOAP encoding across HTTP.  It also specifies namespace and value of the SOAPAction header for the getQuote method.

Lastly, the service section defines the endpoint URL where the service is running.
Example 3 (stockquote.wsdl)

<?xml version='1.0' encoding='UTF-8'?>
<definitions name='StockQuote'
  targetNamespace='http://example.org/StockQuote'
  xmlns:tns=' http://example.org/StockQuote '
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
  xmlns='http://schemas.xmlsoap.org/wsdl/'>

<message name='getQuoteRequest'>
  <part name='symbol' type='xsd:string'/>
</message>
<message name='getQuoteResponse'>
  <part name='Result' type='xsd:float'/>
</message>

<portType name='StockQuotePortType'>
  <operation name='getQuote'>
    <input message='tns:getQuoteRequest'/>
    <output message='tns:getQuoteResponse'/>
  </operation>
</portType>

<binding name='StockQuoteBinding' type='tns:StockQuotePortType'>
  <soap:binding style='rpc'
    transport='http://schemas.xmlsoap.org/soap/http'/>
  <operation name='getQuote'>
    <soap:operation soapAction='urn:xmethods-delayed-quotes#getQuote'/>
    <input>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </input>
    <output>
      <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
    </output>
  </operation>
</binding>

<service name='StockQuoteService'>
  <port name='StockQuotePort' binding='StockQuoteBinding'>
    <soap:address location='http://[insert real path here]/stockquote1.php'/>
  </port>
</service>
</definitions>

Note: The WSDL caching feature is on by default. During the development of your WSDL file it should be turned off.



 
 
>>> More Zend Articles          >>> More By Zend
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZEND ARTICLES

- Taking the Zend Certified PHP Engineer Exam:...
- Quick Introduction to PHP 5
- PHP SOAP Extension
- Improving Performance
- PDFs with PHP part 2
- PDFs with PHP part 1
- PHP at Lycos
- Build Database Interfaces

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: