Soap application-PHP source code

Source: Internet
Author: User
Soap application php SOAP example (web servers)
14:08:24 | Category: php notes | font size subscription
Php must first enable the php_soap module
I.
Method 1
The server file is called server. php.

 "Http: // 10.10.10.24/"); // enter the IP address of the current server $ soap-> addFunction ('say '); // add the output function $ soap-> addFunction (SOAP_FUNCTIONS_ALL); // do not forget this $ soap-> handle (); // pay attention to function say ($ TH) {return $ something ;}?>

The client outputs hello world

 "http://10.10.10.24/server.php",'uri' =>"http://10.10.10.24/")); echo $client->say("hello world");} catch (SoapFault $fault){ echo"Error:",$fault->faultcode,", string:",$fault->faultstring;}?>

II.
Server file server. php:

 "Http: // 10.10.10.24/", "classmap" => $ classmap); $ soap-> setClass ('myclass'); $ soap-> handle (); class Myclass {function say ($ someword) {return $ someword ;}}?>

The customer output is xyz world.

 "http://10.10.10.24/server.php",'uri' =>"http://10.10.10.24/"));var_dump($client); echo $client->say("xyz world");} catch (SoapFault $fault){ echo"Error:",$fault->faultcode,", string:",$fault->faultstring;}
 "Http: // localhost/webserver/soapserver. php ", 'uri '=> 'http: // 127.0.0.1/'); $ soap = new SoapClient (null, array ('location' =>" http: // localhost/webserver/soapserver. php ", 'uri '=> 'test'); // Two call methods: directly call the method, and use _ soapCall to call $ result1 = $ soap-> getName (); $ result2 = $ soap->__ soapCall ("getName", array ()); echo $ result1 ."
"; Echo $ result2;} catch (SoapFault $ e) {echo $ e-> getMessage ();} catch (Exception $ e) {echo $ e-> getMessage () ;}?>
 "Http: // localhost/Test/MyService/Server. php "); // the following two methods can work, as long as the corresponding uri // $ s = new SoapServer (null, array ("uri" => "http: // 127.0.0.1/"); $ s = new SoapServer (null, array ("uri" => "test ")); $ s-> setClass ("PersonInfo"); $ s-> handle ();?>

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.