Advertisement
Guest User

WAPI Web Service PHP Classes Usage

a guest
Jan 27th, 2011
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php
  2. // Load the classes constructed by wsdl2php
  3. require_once 'WAPI.php';
  4.  
  5. // Define the SOAP options.
  6. $a_SoapOptions = array
  7.     (
  8.     'encoding'  => 'UTF-8',
  9.     'exception' => True, // Turn SOAPFaults into Exceptions so PHP can report upon them.
  10.     'trace'     => True, // Turn on tracing so we can see EXACTLY what the headers and request/response are.
  11.     );
  12.  
  13. // As we are going to need to display XML, use Tidy to make it pretty.
  14. $a_TidyConfig = array
  15.     (
  16.     'indent'            => 4,
  17.     'indent-attributes' => true,
  18.     'input-xml'         => true,
  19.     'output-xml'        => true,
  20.     'wrap'              => 0,
  21.     );
  22. $o_Tidy = new Tidy;
  23.  
  24. $s_WsdlUrl = "https://api.ote.wildwestdomains.com/wswwdapi/wapi.asmx?wsdl";
  25.  
  26. // Use a try/catch loop to talk to the services.
  27.  
  28. try
  29.     {
  30.     // Create a login service.
  31.     $o_WAPI = new WAPI($s_WsdlUrl, $a_SoapOptions);
  32.  
  33.     // Create "Describe" and "Credential" objects.
  34.     $o_Describe = new Describe;
  35.     $o_Describe->credential = new Credential;
  36.  
  37.     // Populate newly created objects.
  38.     $o_Describe->sCLTRID              = '';
  39.     $o_Describe->credential->account  = '';
  40.     $o_Describe->credential->password = '';
  41.  
  42.     // Call the describe method of the service.
  43.     $o_DescribeResponse = $o_WAPI->Describe($o_Describe);
  44.  
  45.     // Create a simple object containing the response as the service doesn't do this for us.
  46.     $o_DescribeResults = simplexml_load_string($o_DescribeResponse->DescribeResult);
  47.  
  48.     // Display the results as they are.
  49.     echo print_r($o_DescribeResults, True), PHP_EOL;
  50.  
  51.     }
  52. catch(Exception $e)
  53.     {
  54.     echo PHP_EOL,
  55.  
  56.         // Show trace.
  57.         'Request Headers', PHP_EOL,
  58.         '---------------', PHP_EOL,
  59.         $o_WAPI->__getLastRequestHeaders(), PHP_EOL,
  60.    
  61.         'Request', PHP_EOL,
  62.         '-------', PHP_EOL,
  63.         $o_Tidy->repairString($o_WAPI->__getLastRequest(), $a_TidyConfig), PHP_EOL, PHP_EOL,
  64.        
  65.         'Response Headers', PHP_EOL,
  66.         '----------------', PHP_EOL,
  67.         $o_WAPI->__getLastResponseHeaders(), PHP_EOL,
  68.  
  69.         'Response', PHP_EOL,
  70.         '--------', PHP_EOL,
  71.         $o_Tidy->repairString($o_WAPI->__getLastResponse(), $a_TidyConfig), PHP_EOL, PHP_EOL, PHP_EOL,
  72.  
  73.         // Show exception.
  74.         'Exception', PHP_EOL,
  75.         '---------', PHP_EOL,
  76.         $e->getMessage(), PHP_EOL;
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement