cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1557
Views
1
Helpful
0
Comments
npetrele
Cisco Employee
Cisco Employee

PHP and Cisco SOAP Services

I'll be posting a blog entry soon that shows how to add missing features to PHP and JAXL by using Cisco IM&P's EPASSoap service. EPASSoap lets you add contacts, modify contacts, remove contacts, among many other things. In preparation for that blog post, here are some useful tips for developing PHP applications with Cisco SOAP services.

If you take a look at our AXL PHP Primer, you'll see that the soap client accesses the AXL WSDL as a file. That's because you can download the WSDL and other necessary files from CUCM this way:

Select from the GUI menu Application->Plugins

Click Find and then download the Cisco AXL Toolkit.

There is no equivalent download for WSDLs for other Cisco soap services.  While there are tricks you can play to download Cisco WSDLs, here's how to access them in the PHP soap client via the web.

Assuming you want to access the EPASSoap WSDL, you can direct the PHP soap client to the URL like this, where username and password refer to an account with access to the services (such as the administrator account):

$wsdlURL = "https://".urlencode($username).":".urlencode($password)."@".
               $host."/EPASSoap/service/v105?wsdl";

Now you can instantiate a SOAP client this way:

$client = new SoapClient($wsdlURL,
          array(
               'soap_version' => SOAP_1_2,
               'trace' => true,
               'exceptions' => true,
               'location' => $locationURL,
               'stream_context' => $context,
               'login' => $username,
               'password' => $password));

Note that we define the soap version as 1.2.  Most Cisco SOAP services use soap 1.1, which is the default for the PHP SOAP client. EPASSoap requires 1.2, so we need to specify 1.2 in the client parameters.

We're not home clear yet, though.  Many Cisco IM&P servers use self-signed certificates, so we need to set up some context parameters to allow https access to the WSDL.

Before you instantiate the SOAP client above, you need to set up the stream_context.  Here's one approach that works for our lab:

$context = stream_context_create([
     'ssl' => [
          // set some SSL/TLS specific options
          'verify_peer' => false,
          'verify_peer_name' => false,
          'allow_self_signed' => true,
     ]
]);

Assuming you've got all the other parameters set correctly, you should be able to construct a client that connects and can communicate with the server.

But wait, there's more!   Let's extend the PHP SoapClient to add a few new features.

  • The option to send or not send a SOAP request
  • The option to print the request XML
  • The option to print the request XML in a way that's formatted for easy reading

These added features make it easy to experiment by viewing the XML requests without necessarily sending them to the server. Optionally, you can preview the XML requests and still send them. Just enable/disable the options at your convenience.

In the sample below, the extended SoapClient behaves the same as the standard PHP SoapClient unless otherwise specified.  And we do specify otherwise after instantiating the client.

Working Sample

<?php
$host = "CIMP Server";
$username = "username";
$password = "password";
$locationURL = "https://".$host."/EPASSoap/service/v105";
$wsdlURL = "https://".urlencode($username).":".urlencode($password)."@".
               $host."/EPASSoap/service/v105?wsdl";

class MySoapClient extends SoapClient {
     public $sendRequest = true;
     public $printRequest = false;
     public $formatXML = false;

     public function __doRequest($request, $location, $action, 
                                        $version, $one_way = 0) {
          if ($this->printRequest) {
               if (!$this->formatXML) {
                    $out = $request;
               } else {
                    $doc = new DOMDocument;
                    $doc->preserveWhiteSpace = false;
                    $doc->loadxml($request);
                    $doc->formatOutput = true;
                    $out = $doc->savexml();
               }
               echo "<pre>";
               echo htmlspecialchars($out);
               echo "</pre>";
          }

          if ($this->sendRequest) {
               return parent::__doRequest($request, $location, 
                                                  $action, $version, $one_way);
          } else {
               return '';
          }
     }
}

$clientClass = 'MySoapClient';

$context = stream_context_create([
     'ssl' => [
          // set some SSL/TLS specific options
          'verify_peer' => false,
          'verify_peer_name' => false,
          'allow_self_signed' => true,
     ]
]);

$client = new $clientClass($wsdlURL,
          array(
               'soap_version' => SOAP_1_2,
               'trace' => true,
               'exceptions' => true,
               'location' => $locationURL,
               'stream_context' => $context,
               'login' => $username,
               'password' => $password));
               
$client->sendRequest = false;
$client->printRequest = true;
$client->formatXML = true;

Now stay tuned for how we're going to use this with EPASSoap in an upcoming blog post.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: