cvs: pear /SOAP/example client.php server.php stockquote.php

From: Date: Sat, 27 Apr 2002 17:53:01 +0000
Subject: cvs: pear /SOAP/example client.php server.php stockquote.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3583@lists.php.net to get a copy of this message
shane Sat Apr 27 13:53:01 2002 EDT Added files: /pear/SOAP/example client.php server.php Modified files: /pear/SOAP/example stockquote.php Log: add some basic examples of server/client Index: pear/SOAP/example/stockquote.php diff -u pear/SOAP/example/stockquote.php:1.2 pear/SOAP/example/stockquote.php:1.3 --- pear/SOAP/example/stockquote.php:1.2 Tue Mar 19 03:25:25 2002 +++ pear/SOAP/example/stockquote.php Sat Apr 27 13:53:01 2002 @@ -18,7 +18,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: stockquote.php,v 1.2 2002/03/19 08:25:25 shane Exp $ +// $Id: stockquote.php,v 1.3 2002/04/27 17:53:01 shane Exp $ // // include soap client class include("SOAP/Client.php"); @@ -38,7 +38,14 @@ print "\n<br><strong>non wsdl:</strong>"; $soapclient = new SOAP_Client("http://services.xmethods.net:80/soap"); -$ret = $soapclient->call("getQuote",array("symbol"=>"ibm"),"urn:xmethods-delayed-quotes","urn:xmethods-delayed-quotes#getQuote"); +$namespace = "urn:xmethods-delayed-quotes"; +/** + * some soap servers require a Soapaction http header. PEAR::SOAP does + * not use them in any way, other to send them if you supply them. + * soapaction is deprecated in later SOAP versions. + */ +$soapaction = "urn:xmethods-delayed-quotes#getQuote"; +$ret = $soapclient->call("getQuote",array("symbol"=>"ibm"),$namespace,$soapaction); print_r($ret); print "\n\n"; unset($soapclient); Index: pear/SOAP/example/client.php +++ pear/SOAP/example/client.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // // $Id: client.php,v 1.1 2002/04/27 17:53:01 shane Exp $ // include("SOAP/Client.php"); /** * this client runs against the example server in SOAP/example/server.php */ $soapclient = new SOAP_Client("http://localhost/SOAP/example/server.php"); // this namespace is the same as declared in server.php $namespace = 'urn:SOAP_Example_Server'; $ret = $soapclient->call("echoStringSimple",array("inputString"=>"this is a test string"),$namespace); print_r($ret);echo "<br>\n"; $ret = $soapclient->call("echoString",array("inputString"=>"this is a test string"),$namespace); print_r($ret);echo "<br>\n"; $SOAPStruct = array('inputStruct' => array('varString'=>'this is a test string', 'varInt'=>12345, 'varFloat'=>123.456)); /** * PHP doesn't support multiple OUT parameters in function calls, so we * must do a little work to make it happen here. This requires knowledge on the * developers part to figure out how they want to deal with it. */ list($string, $int, $float) = array_values($soapclient->call("echoStructAsSimpleTypes",$SOAPStruct,$namespace)); echo "varString: $string<br>\nvarInt: $int<br>\nvarFloat: $float<br>\n"; ?> Index: pear/SOAP/example/server.php +++ pear/SOAP/example/server.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Shane Caraveo <Shane@Caraveo.com> | // +----------------------------------------------------------------------+ // // $Id: server.php,v 1.1 2002/04/27 17:53:01 shane Exp $ // // first, include the SOAP/Server class require_once 'SOAP/Server.php'; $server = new SOAP_Server; // create a class for your soap functions class SOAP_Example_Server { /** * method namespace can be whatever you desire, the client * must match it when it makes calls to you * * example namespaces * urn:SOAP_Example_Server * http://myserver.com/SOAP_Example_Server */ var $method_namespace = 'urn:SOAP_Example_Server'; /** * The dispactch map does not need to be used, but aids * the server class in knowing what parameters are used * with the functions. This is the ONLY way to have * multiple OUT parameters */ var $dispatch_map = array(); function SOAP_Interop_GroupB() { // the one function here has multiple out parameters $this->dispatch_map['echoStructAsSimpleTypes'] = array('in' => array('inputStruct' => 'SOAPStruct'), 'out' => array('outputString' => 'string', 'outputInteger' => 'int', 'outputFloat' => 'float') ); } // a simple echoString function function echoStringSimple($inputString) { return $inputString; } // an explicit echostring function function echoString($inputString) { return new SOAP_Value('outputString','string',$inputString); } /** * echoStructAsSimpleTypes * takes a SOAPStruct as input, and returns each of its elements * as OUT parameters * * SOAPStruct is defined as: * * struct SOAPStruct: * string varString * integer varInt * float varFloat * */ function echoStructAsSimpleTypes ($struct) { # convert a SOAPStruct to an array return array( new SOAP_Value('outputString','string',$struct['varString']), new SOAP_Value('outputInteger','int',$struct['varInt']), new SOAP_Value('outputFloat','float',$struct['varFloat']) ); } } $soapclass = new SOAP_Example_Server(); $server->addObjectMap($soapclass); $server->service($HTTP_RAW_POST_DATA); ?>

« previous php.pear.cvs (#3583) next »