client.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: client.php,v 1.8 2003/04/13 21:38:59 shane Exp $
  20. //
  21. include("SOAP/Client.php");
  22. /**
  23. * this client runs against the example server in SOAP/example/server.php
  24. * it does not use WSDL to run these requests, but that can be changed easily by simply
  25. * adding '?wsdl' to the end of the url.
  26. */
  27. $soapclient = new SOAP_Client("http://localhost/SOAP/example/server.php");
  28. // this namespace is the same as declared in server.php
  29. $options = array('namespace' => 'urn:SOAP_Example_Server',
  30. 'trace' => 1);
  31. $ret = $soapclient->call("echoStringSimple",
  32. $params = array("inputStringSimple"=>"this is a test string"),
  33. $options);
  34. #print $soapclient->__get_wire();
  35. print_r($ret);echo "<br>\n";
  36. $ret = $soapclient->call("echoString",
  37. $params = array("inputString"=>"this is a test string"),
  38. $options);
  39. print_r($ret);echo "<br>\n";
  40. $ret = $soapclient->call("divide",
  41. $params = array("dividend"=>22,"divisor"=>7),
  42. $options);
  43. # print $soapclient->__get_wire();
  44. if (PEAR::isError($ret))
  45. print("Error: " . $ret->getMessage() . "<br>\n");
  46. else
  47. print("Quotient is " . $ret . "<br>\n");
  48. $ret = $soapclient->call("divide",
  49. $params = array("dividend"=>22,"divisor"=>0),
  50. $options);
  51. if (PEAR::isError($ret))
  52. print("Error: " . $ret->getMessage() . "<br>\n");
  53. else
  54. print("Quotient is " . $ret . "<br>\n");
  55. // SOAPStruct is defined in the following file
  56. require_once 'example_types.php';
  57. $struct = new SOAPStruct('test string',123,123.123);
  58. /* send an object, get an object back */
  59. /* tell client to translate to classes we provide if possible */
  60. $soapclient->_auto_translation = true;
  61. /* or you can explicitly set the translation for
  62. a specific class. auto_translation works for all cases,
  63. but opens ANY class in the script to be used as a data type,
  64. and may not be desireable. both can be used on client or
  65. server */
  66. $soapclient->__set_type_translation('{http://soapinterop.org/xsd}SOAPStruct','SOAPStruct');
  67. $ret = $soapclient->call("echoStruct",
  68. $p = array('inputStruct' => $struct->__to_soap()),
  69. $options);
  70. #print $soapclient->__get_wire();
  71. print_r($ret);
  72. /**
  73. * PHP doesn't support multiple OUT parameters in function calls, so we
  74. * must do a little work to make it happen here. This requires knowledge on the
  75. * developers part to figure out how they want to deal with it.
  76. */
  77. $ret = $soapclient->call("echoStructAsSimpleTypes",
  78. $p = array('inputStruct' => $struct->__to_soap()),
  79. $options);
  80. if (PEAR::isError($ret)) {
  81. print("Error: " . $ret->getMessage() . "<br>\n");
  82. } else {
  83. list($string, $int, $float) = array_values($ret);
  84. }
  85. echo "varString: $string<br>\nvarInt: $int<br>\nvarFloat: $float<br>\n";
  86. ?>