Call web service + PHP SOAP

SOAP (Simple Object Access Protocol) is very important for create and consume web services. Here I’ve explained how to call a web service using PHP SOAP.

I’ve created 2 classes for web service, one is WebServiceConfig and another one is WebService.

  1. WebServiceConfig is abstract class and it’s only configuration variables. You must change WSDL URL variable.
  2. WebService is a class for implementing web service, the class created based on signleton design patten. So doesn’t create objects using “new” keyword. Use “getInstance()” static function and get the object of “WebService” class.

Create object for “WebService” class.

$ws = WebService::getInstance();

Call getFunctions() function, It returns all available functions in web services

Call function without any parameters.

$function_name = 'GetAtoms';

$result = $ws->callFunction($function_name);

“GetAtoms” is a web service function name, it’s no parameters,

Call function with parameters

We send a request in two ways.

1. XML format

2. Assosiative array format

Assosiative array format is simple and readable, it’s more convinient compare with xml format. Here i’ve used assosiative array format.

//            Call function with parameter

$function_name = 'GetElementSymbol';

$params = array('ElementName' => 'Iron');

$result = $ws->callFunction($function_name, $params);

Demo

Download
Do you want more information SOAP, please check my next article in this category.

Popularity: 6% [?]

Related posts:

  1. REST or SOAP – Which is the best web service?
  2. How to call the web services through PHP?
  3. How to send xml request to web service through php
  4. How to call functions in dynamically + JavaScript
  5. PHP 6 Features

3 thoughts on “Call web service + PHP SOAP

  1. Pingback: Zeenor - Set SOAP header in PHP

  2. Pingback: Zeenor - PHP SOAP: Send XML parameter instead of array / associative array

  3. I in addition to my pals have been following the great tactics on your web site and instantly I got a terrible suspicion I had not thanked the web site owner for them. My ladies came as a consequence thrilled to read them and have in effect pretty much been taking pleasure in them. I appreciate you for being quite kind as well as for utilizing this sort of fabulous subjects most people are really eager to understand about. My very own sincere apologies for not saying thanks to sooner.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


eight − = 6

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>