Home > PHP > Creating SOAP client with PHP, simple version

Creating SOAP client with PHP, simple version


Using SOAP with PHP is very straight forward and easy. Using the SoapClient class and the servers WSDL file as reference, you’re good to go.

Instansiate a SOAP client towards a specified url;

define('WSDL', 'http://www.example.com/service.asmx?wsdl');
$client = new SoapClient(WSDL, array($options));  //options are... optional :) 

Since we are using WSDL, we can use the servers SOAP functions just as local methods! Lets say there’s a function called GetUserById($id); that returns a GetUserByIdResponse.  Here’s how we call it print the response.

$response = $client->GetUserById(array('id' => $id));
print_r($response->GetUserByIdRespons);

Really simple.

For more advanced usage of SOAP + PHP, building your own classes for input control etc, check out the post coming later this week.

Categories: PHP
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.