0

Simple PHP SOAP Client Example

Background

This article demonstrates how to create an SOAP client using PHP and consume a SOAP-based web service

Hardware Environment

n/a

Software Environment

  • Windows 7 Professional SP1
  • PHP 5.5.9 / Zend Engine v2.5.0

Find a free Web Service Online

First, find a free web service online to test. For this post, the StockQuote service is used which is available on www.webservicex.net.

php-soap-client-ws1

 

Open the WSDL on the browser.

php-soap-client-ws-002_wm

 

A new tab will open showing the content of WSDL we chose.

php-soap-client-ws-003_wm

Next, we look for a SOAP-based operation and look at its input and output messages. There are 3 operations in this WSDL but we are only interested “GetQuote” under the “StockQuoteSoap” portType.

php-soap-client-ws-004_wm

 

GetQuote operation

php-soap-client-ws-005_wm

Using PHP

Then, we look for the element  “GetOute” used in the “GetQuoteSoapIn”. It represents the “parameters” that we need to pass to get some meaningful output. Also, take note of the “GetQuoteResult” within the “GetQuoteResponse” element. We will use that to read the value from the web service response in PHP.

php-soap-client-ws-006_wm

With those information, we can know code our PHP client to execute a SOAP operation.

Sample Output

jet-brain-soap-ws-001_wm