Example of using soap in PHP _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.