Creating SOAP client with PHP, simple version
2009/11/09
Leave a comment
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
Recent Comments