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 ();?>