You can find this artical at http://www.gigaideas.com.cn/phpsoap
SOAP Client and Server for PHP
This is a PHP implementation of the SOAP submission to W3C.SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses.
Download soap_php.zip here.
http://www.gigaideas.com.cn/phpsoap/soap_php.zip
How to install:
Ensure that you have compiled PHP with --with-xml option.
We assume that you have downloaded this distribution of SOAP Client and Server for PHP and place soap_client.inc into your PHP Include Directory,then you are ready to use SOAP Client!
If you want to use your SOAP Server for PHP,you should place rpcrouter.php in any of your web directories
other than above step.
How to use:
Here is a sample code that use PHP invoke JAVA class:
CLient Side Program Written in PHP:
<?
require "soap_client.inc"; //First step in our program,don't forget!
//Build the call.
$send_int=2001;
$send_string="happy!";
$send_arr=array("2001","happy" );
$soap_msg=new soapmsg( 'get_array', //Invoke Method Name
'urn:soap_test', //Invoke Target Object Id
array( //Parametres List Below
new soapval($send_int,"int"),
new soapval($send_string,"string"),
new soapval($send_arr, "array")));
//Invoke the call.
$client=new soap_client("/soap/servlet/rpcrouter", "office.gigaideas.com.cn", 8080);
Note: /soap/servlet/rpcrouter is soap server side servlet program.
office.gigaideas.com.cn & 8080 is server name and port.
$return=$client->send($soap_msg);
if (!$return) { die("send failed"); }
$v=$return->value();
//Check the response.
if(!$return->faultCode()) {
$back_arr=$v->scalarval();
print "Back array is:\n<br>";
for($i=0;$i<sizeof($back_arr);$i++) echo $i." => ".$back_arr[$i]."\n<br>";
} else {
print "Fault: ";
print "Code: " . $return->faultCode() . " Reason '" .$return->faultString()."'<BR>";
}
?>
Server Side Program Written in JAVA:
package samples.soaptest;
import java.io.;
import java.util.;
import java.lang.*;
public class soap_test {
public int get_int(int x,String y,Object[] z) {
return x;
}
public String get_string(int x,String y,Object[] z) {
return y;
}
public Vector get_array(int x,String y,Object[] z) {
Vector params = new Vector (); //Turn array into Vector
for(int i=0;i<z.length;i++) { //Add element to Vector
String param_type=z.getClass().getName();
if(param_type=="java.lang.String")
params.addElement((String)z);
else if(param_type=="java.lang.Integer")
params.addElement((Integer)z);
else if(param_type=="java.lang.Double")
params.addElement((Double)z);
else
params.addElement((String)z);
}
//Now we can operate this Vector
//ToDo Something Here
return params; //Return this Vector
}
}
¡¡
Here is a sample code that use JAVA invoke PHP function:
Part of CLient Side Program Written in JAVA:
// Build the call.
Call call = new Call ();
call.setTargetObjectURI ("functions.inc"); //Invoke Target Function Filename
call.setMethodName ("plus"); //Invoke Method Name
call.setEncodingStyleURI(encodingStyleURI);
Vector params = new Vector ();
params.addElement (new Parameter("params1", double.class,new Double (arg1), null));
params.addElement (new Parameter("params2", double.class,new Double (arg2), null));
call.setParams (params);
Note: param name should named as param+n when you use This PHP SOAP Server.
// make the call
Response resp = call.invoke ( "http://office.gigaideas.com.cn/soap_php_server/rpcrouter.php,"" );
//http://office.gigaideas.com.cn/soap_php_server/rpcrouter.php is SOAP Server side php program.
Server Side Program Written in PHP:
<?
//filename:functions.inc
function plus($x,$y) {
$z=$x+$y;
return $z;
}
?>
Declaration:
The sample list above has been tested successfully under SOAP2.1 .
All data types supported except object.
Examples:
I.soaptest.php
II.soaptest_struct.php
Any problem or suggestion click here.¡¡