Software Development

Simple PHP SOAP Client Example

Background

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

[wp_ad_camp_1]

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.

[wp_ad_camp_2]

php-soap-client-ws-002_wm

 

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

php-soap-client-ws-003_wm

[wp_ad_camp_3]

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

[wp_ad_camp_4]

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

[wp_ad_camp_5]

jet-brain-soap-ws-001_wm

 

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like