Advertisement
Guest User

consume.php

a guest
Jul 10th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <?php
  2. // Load the classes constructed by wsdl2php
  3. require_once 'ecmasService.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 = "a.wsdl"; // Using a local edited copy of the wsdl you posted.
  25.  
  26. // Use a try/catch loop to talk to the services.
  27.  
  28. try
  29.     {
  30.     // Create a service.
  31.     $o_Service = new ecmasService($s_WsdlUrl, $a_SoapOptions);
  32.  
  33.     // Create the parameters
  34.     $o_UserLoginParams = new userLogin;
  35.     $o_UserLoginParams->username = 'MyUsername';
  36.     $o_UserLoginParams->password = 'MyPassword';
  37.  
  38.     // Call the method.
  39.     $o_UserLoginResponse = $o_Service->userLogin($o_UserLoginParams);
  40.  
  41.     // Extract the results.
  42.     $s_Token = $o_UserLoginResponse->token;
  43.    
  44.     // For some services, the results are raw XML and not a WSDL provided complex type. If this is the case, convert the XML to a simplexml object.
  45.     // $o_HelloWorldResults = simplexml_load_string($o_HelloWorldResponse->HelloWorldResult;);
  46.  
  47.     // Display the results as they are.
  48.     echo PHP_EOL,
  49.  
  50.         // Show trace.
  51.         'Request Headers', PHP_EOL,
  52.         '---------------', PHP_EOL,
  53.         $o_Service->__getLastRequestHeaders(), PHP_EOL,
  54.  
  55.         'Request', PHP_EOL,
  56.         '-------', PHP_EOL,
  57.         $o_Tidy->repairString($o_Service->__getLastRequest(), $a_TidyConfig), PHP_EOL, PHP_EOL,
  58.  
  59.         'Response Headers', PHP_EOL,
  60.         '----------------', PHP_EOL,
  61.         $o_Service->__getLastResponseHeaders(), PHP_EOL,
  62.  
  63.         'Response', PHP_EOL,
  64.         '--------', PHP_EOL,
  65.         $o_Tidy->repairString($o_Service->__getLastResponse(), $a_TidyConfig), PHP_EOL, PHP_EOL, PHP_EOL,
  66.  
  67.         'Response interpreted', PHP_EOL,
  68.         '--------------------', PHP_EOL,
  69.         print_r($s_Token, True), PHP_EOL;
  70.  
  71.     }
  72. catch(Exception $e)
  73.     {
  74.     echo PHP_EOL,
  75.  
  76.         // Show trace.
  77.         'Request Headers', PHP_EOL,
  78.         '---------------', PHP_EOL,
  79.         $o_Service->__getLastRequestHeaders(), PHP_EOL,
  80.  
  81.         'Request', PHP_EOL,
  82.         '-------', PHP_EOL,
  83.         $o_Tidy->repairString($o_Service->__getLastRequest(), $a_TidyConfig), PHP_EOL, PHP_EOL,
  84.  
  85.         'Response Headers', PHP_EOL,
  86.         '----------------', PHP_EOL,
  87.         $o_Service->__getLastResponseHeaders(), PHP_EOL,
  88.  
  89.         'Response', PHP_EOL,
  90.         '--------', PHP_EOL,
  91.         $o_Tidy->repairString($o_Service->__getLastResponse(), $a_TidyConfig), PHP_EOL, PHP_EOL, PHP_EOL,
  92.  
  93.         // Show exception.
  94.         'Exception', PHP_EOL,
  95.         '---------', PHP_EOL,
  96.         $e->getMessage(), PHP_EOL;
  97.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement