itopsoap.examples.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. require_once('itopsoaptypes.class.inc.php');
  3. $sItopRoot = 'http'.(empty($_SERVER['HTTPS']) ? '' : 's').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/..';
  4. $sWsdlUri = $sItopRoot.'/webservices/itop.wsdl.php';
  5. ini_set("soap.wsdl_cache_enabled","0");
  6. $oSoapClient = new SoapClient(
  7. $sWsdlUri,
  8. array(
  9. 'trace' => 1,
  10. 'classmap' => $aSOAPMapping, // defined in itopsoaptypes.class.inc.php
  11. )
  12. );
  13. try
  14. {
  15. // The most simple service, returning a string
  16. //
  17. $sServerVersion = $oSoapClient->GetVersion();
  18. echo "<p>GetVersion() returned <em>$sServerVersion</em></p>";
  19. // More complex ones, returning a SOAPResult structure
  20. // (run the page to know more about the returned data)
  21. //
  22. $oRes = $oSoapClient->CreateIncidentTicket
  23. (
  24. 'admin', /* login */
  25. 'admin', /* password */
  26. 'Server', /* type */
  27. 'Email server down', /* description */
  28. 'HW found shutdown', /* initial situation */
  29. 'Email not working', /* impact */
  30. null, /* caller */
  31. new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', 'Demo'))), /* customer */
  32. new SOAPExternalKeySearch(array(new SOAPSearchCondition('id', 1))), /* workgroup */
  33. array(
  34. new SOAPLinkCreationSpec(
  35. 'bizDevice',
  36. array(new SOAPSearchCondition('name', 'Router03')),
  37. array(new SOAPAttributeValue('impact', 'root cause'))
  38. ),
  39. new SOAPLinkCreationSpec(
  40. 'bizServer',
  41. array(new SOAPSearchCondition('name', 'Server01')),
  42. array(new SOAPAttributeValue('impact', ''))
  43. ),
  44. ), /* impact */
  45. 'high' /* severity */
  46. );
  47. echo "<p>CreateIncidentTicket() returned:\n";
  48. echo "<pre>\n";
  49. print_r($oRes);
  50. echo "</pre>\n";
  51. echo "</p>\n";
  52. }
  53. catch(SoapFault $e)
  54. {
  55. echo "<h1>SoapFault Exception: {$e->getMessage()}</h1>\n";
  56. echo "<h2>Request</h2>\n";
  57. echo "<pre>\n";
  58. echo htmlspecialchars($oSoapClient->__getLastRequest())."\n";
  59. echo "</pre>";
  60. echo "<h2>Response</h2>";
  61. echo $oSoapClient->__getLastResponse()."\n";
  62. }
  63. ?>