Example of using soap in PHP. Example of using soap in PHP: There are two methods for using soap in PHP. 1. use the wsdl file server .? Php {publicfunctionHelloWorld () {returnHello;} publicfunctionAdd ($ a, $ B) {example of soap use in re PHP
PHP uses soap in two ways.
1. use the wsdl file
Server.
{
Public function HelloWorld ()
{
Return "Hello ";
}
Public function Add ($ a, $ B)
{
Return $ a + $ B;
}
}
$ Server = new SoapServer ('soap. wsdl ', array ('soap _ version' => SOAP_1_2 ));
$ Server-> setClass ("service ");
$ Server-> handle ();
?>
Resource Description File, which can be generated using zend studio. It is actually an xml file.
Transport = "http://schemas.xmlsoap.org/soap/http"/>
Namespace = "http: // localhost/interface/"/>
Namespace = "http: // localhost/interface/"/>
Client call
$ Soap = new SoapClient ('http: // localhost/interface/soap. wsdl ');
Echo $ soap-> Add (1, 2 );
?>
2. do not use the wsdl file
Server
{
Public function HelloWorld ()
{
Return "Hello ";
}
Public function Add ($ a, $ B)
{
Return $ a + $ B;
}
}
$ Server = new SoapServer (null, array ('uri '=> "abcd "));
$ Server-> setClass ("service ");
$ Server-> handle ();
?>
Client Try {
$ Soap = new SoapClient (null, array (
"Location" => "http: // localhost/interface/soap. php ",
"Uri" => "abcd", // The Resource Descriptor server and client must correspond
"Style" => SOAP_RPC,
"Use" => SOAP_ENCODED
));
Echo $ soap-> Add (1, 2 );
} Catch (Exction $ e ){
Echo print_r ($ e-> getMessage (), true );
}
?>
PHP uses soap in two ways. 1. use the wsdl file server. ? Php {public function HelloWorld () {return Hello;} public function Add ($ a, $ B) {re...