Home arrow PHP arrow Page 4 - Using XPath, SOAP, and More with Web Services

PHP’s SOAP Extension - PHP

In this fourth part of a five-part series on Web Services, you'll learn about SimpleXML objects, SOAP, 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. Using XPath, SOAP, and More with Web Services
  2. Using XPath to Retrieve Node Information
  3. SOAP
  4. PHP’s SOAP Extension
By: Apress Publishing
Rating: starstarstarstarstar / 2
August 09, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In response to the community clamor for Web Services–enabled applications, and the popularity of third-party SOAP extensions, a native SOAP extension was available as of PHP 5, and enabled by default as of PHP 6.0. This section introduces this object-oriented extension and shows you how to create both a SOAP client and server. Along the way you’ll learn more about many of the functions and methods available through this extension. Before you can follow along with the accompanying examples, you need to take care of a few prerequisites, which are discussed next.

Prerequisites

PHP’s SOAP extension requires the GNOME XML library. You can download the latest stablelibxml2package fromhttp://www.xmlsoft.org/. Binaries are also available for the Windows platform. Version 2.5.4 or greater is required. If you’re running a version of PHP older than 6.0, you’ll also need to configure PHP with the--enable-soapextension. On Windows, you’ll need to add the following line to yourphp.inifile:

extension=php_soap.dll

Instantiating the Client

The SoapClient() constructor instantiates a new instance of the SoapClient class. The prototype looks like this:

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

Thewsdlparameter determines whether the class will be invoked in WSDL or non-WSDL mode; if in WSDL mode, set it to the WSDL file URI, otherwise set it toNULL. Theoptionsparameter is an array that accepts the following parameters. It’s optional for WSDL mode and requires that at least thelocationandurl options are set when in non-WSDL mode:

actor: This parameter specifies the name, in URI format, of the role that a SOAP node must play in order to process the header.

compression: This parameter specifies whether data compression is enabled. Presently, Gzip and x-gzip are supported. According to the TODO document, support is planned for HTTP compression.

exceptions: This parameter turns on the exception-handling mechanism. It is enabled by default.

location: This parameter is used to specify the endpoint URL, when working in non-WSDL mode.

login: This parameter specifies the username if HTTP authentication is used to access the SOAP server.

password: This parameter specifies the password if HTTP authentication is used to access the SOAP server.

proxy_host: This parameter specifies the name of the proxy host when connecting through a proxy server.

proxy_login: This parameter specifies the proxy server username if one is required.

proxy_password: This parameter specifies the proxy server password if one is required.

proxy_port: This parameter specifies the proxy server port when connecting through a proxy server.

soap_version: This parameter specifies whether SOAP version 1.1 or 1.2 should be used. This defaults to version 1.1.

trace: This parameter specifies whether you’d like to examine SOAP request and response envelopes. If so, you’ll need to enable this by setting it to 1.

uri: This parameter specifies the SOAP service namespace when not working in WSDL mode.

Establishing a connection to a Web Service is trivial. The following example shows you how to use theSoapClientobject to connect to a sports-related Web service I’ve created to retrieve a random boxing quote:

<?php 
   
$ws = http://www.wjgilmore.com/boxing.wsdl;
    $client = new SoapClient($ws);
?>

However, just referencing the Web Service really doesn’t do you much good. You’ll want to learn more about the methods exposed by this Web Service. Of course, you can open up the WSDL document in the browser or a WSDL viewer by navigating tohttp://www.wjgilmore.com/boxing.wsdl. However, you can also retrieve the methods programmatically using the__getFunctions()method, introduced next.

Please check back for the conclusion to this series.



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