PHPwebservice instance. First, you need to briefly understand what webservice is. next we will give two very simple examples. webservice still cannot escape the server and client. In my testing environment: apache2.2.11, you should first understand what webservice is. Next, we will give two very simple examples. webservice cannot escape the server and client.
My testing environment is apache2.2.11 php5.2.10.
Before doing this test, make sure that the soap extension has been opened in your php configuration file, that is, extension = php_soap.dll;
OK. Now let's try webservice.
// Server-side serverSoap. php
$ Soap = new SoapServer (null, array ('uri '=> "http: // 192.168.1.179/"); // This uri is the ip address of the your SERVER.
$ Soap-> addFunction ('minus _ func'); // Register the function
$ Soap-> addFunction (SOAP_FUNCTIONS_ALL );
$ Soap-> handle ();
Function minus_func ($ I, $ j ){
$ Res = $ I-$ j;
Return $ res;
}
// Client soap. php
Try {
$ Client = new SoapClient (null,
Array ('location' => "http: // 192.168.1.179/test/serverSoap. php", 'URL' => "http: // 127.0.0.1 /")
);
Echo $ client-> minus_func (100,99 );
} Catch (SoapFault $ fault ){
Echo "Error:", $ fault-> faultcode, ", string:", $ fault-> faultstring;
}
This is an example of a client calling a server function. let's create another class.
// ServerSoap. php on www.2cto.com server
$ ClassExample = array ();
$ Soap = new SoapServer (null, array ('URL' => "http: // 192.168.1.179/", 'classexample '=> $ classExample ));
$ Soap-> setClass ('chesterclass ');
$ Soap-> handle ();
Class chesterClass {
Public $ name = 'Chester ';
Function getName (){
Return $ this-> name;
}
}
// Client soap. php
Try {
$ Client = new SoapClient (null,
Array ('location' => "http: // 192.168.1.179/test/serverSoap. php", 'URL' => "http: // 127.0.0.1 /")
);
Echo $ client-> getName ();
} Catch (SoapFault $ fault ){
Echo "Error:", $ fault-> faultcode, ", string:", $ fault-> faultstring;
}
Author: Fox Warrior
Bytes. My testing environment is: apache2.2.11...