source: branches/version-2_11-dev/data/module/SOAP/example/client.php @ 21304

Revision 21304, 3.7 KB checked in by kotani, 12 years ago (diff)

#1521 (PEAR::SOAP 配布と異なる部分がある)

  • 新しいバージョンの配布ファイルを上書きすることで解決
  • →2.11.4には含めないため一旦コミットキャンセル

#1522 (PEAR::SOAP をバージョンアップ)

  • 0.11.0 -> 0.12.0
  • →2.11.4には含めないため一旦コミットキャンセル
  • Property svn:eol-style set to LF
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/**
3 * This file contains an example SOAP client that calls methods on the example
4 * SOAP server in this same directory.
5 *
6 * PHP versions 4 and 5
7 *
8 * LICENSE: 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 available at
10 * through the world-wide-web at http://www.php.net/license/2_02.txt.  If you
11 * did not receive a copy of the PHP license and are unable to obtain it
12 * through the world-wide-web, please send a note to license@php.net so we can
13 * mail you a copy immediately.
14 *
15 * @category   Web Services
16 * @package    SOAP
17 * @author     Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more
18 * @copyright  2003-2005 The PHP Group
19 * @license    http://www.php.net/license/2_02.txt  PHP License 2.02
20 * @link       http://pear.php.net/package/SOAP
21 */
22
23require 'SOAP/Client.php';
24
25/**
26 * This client runs against the example server in SOAP/example/server.php.  It
27 * does not use WSDL to run these requests, but that can be changed easily by
28 * simply adding '?wsdl' to the end of the url.
29 */
30$soapclient = new SOAP_Client('http://localhost/SOAP/example/server.php');
31// This namespace is the same as declared in server.php.
32$options = array('namespace' => 'urn:SOAP_Example_Server',
33                 'trace' => true);
34
35$ret = $soapclient->call('echoStringSimple',
36                         $params = array('inputStringSimple' => 'this is a test string'),
37                         $options);
38// print $soapclient->getWire();
39print_r($ret);
40echo "<br>\n";
41
42$ret = $soapclient->call('echoString',
43                         $params = array('inputString' => 'this is a test string'),
44                         $options);
45print_r($ret);
46echo "<br>\n";
47
48$ret = $soapclient->call('divide',
49                         $params = array('dividend' => 22, 'divisor' => 7),
50                         $options);
51// print $soapclient->getWire();
52if (PEAR::isError($ret)) {
53    echo 'Error: ' . $ret->getMessage() . "<br>\n";
54} else {
55    echo 'Quotient is ' . $ret . "<br>\n";
56}
57
58$ret = $soapclient->call('divide',
59                         $params = array('dividend' => 22, 'divisor' => 0),
60                         $options);
61if (PEAR::isError($ret)) {
62    echo 'Error: ' . $ret->getMessage() . "<br>\n";
63} else {
64    echo 'Quotient is ' . $ret . "<br>\n";
65}
66
67
68// SOAPStruct is defined in the following file.
69require_once 'example_types.php';
70
71$struct = new SOAPStruct('test string', 123, 123.123);
72
73/* Send an object, get an object back. Tell the client to translate to classes
74 * we provide if possible. */
75$soapclient->_auto_translation = true;
76/* You can explicitly set the translation for a specific
77 * class. auto_translation works for all cases, but opens ANY class in the
78 * script to be used as a data type, and may not be desireable. Both can be
79 * used on client or server. */
80$soapclient->setTypeTranslation('{http://soapinterop.org/xsd}SOAPStruct',
81                                'SOAPStruct');
82$ret = $soapclient->call('echoStruct',
83                         $p = array('inputStruct' => $struct->__to_soap()),
84                         $options);
85// print $soapclient->getWire();
86print_r($ret);
87
88/**
89 * PHP doesn't support multiple OUT parameters in function calls, so we must
90 * do a little work to make it happen here.  This requires knowledge on the
91 * developers part to figure out how they want to deal with it.
92 */
93$ret = $soapclient->call('echoStructAsSimpleTypes',
94                         $p = array('inputStruct' => $struct->__to_soap()),
95                         $options);
96if (PEAR::isError($ret)) {
97    echo 'Error: ' . $ret->getMessage() . "<br>\n";
98} else {
99    list($string, $int, $float) = array_values($ret);
100    echo "varString: $string<br>\nvarInt: $int<br>\nvarFloat: $float<br>\n";
101}
Note: See TracBrowser for help on using the repository browser.