1. First download the PHP WebService package: nusoap, and download it on the official website. The link is not provided. go to Google.
Based on nosoap, we wrote a PHP WebService server. The example is as follows:
<? PHP
Header ("Content-Type: text/html; charset = UTF-8 ");
Require ('../lib/nusoap. php ');
$ Server = new soap_server ();
$ Server-> configurewsdl ('hellowsdl ', 'urn: hellowsdl ');
$ Server-> WSDL-> schematargetnamespace = 'urn: hellowsdl ';
$ Server-> Register ('hello', // method name
Array ('name' => 'xsd: string'), // input parameters
Array ('Return '=> 'xsd: string'), // output parameters
'Urn: hellowsdl ', // namespace
'Urn: hellowsdl # hellowsdl ', // soapaction
'Rpc ', // Style
'Encoded', // use
'Says hello to the caller' // documentation
);
Function Hello ($ name ){
If ($ name = ''){
Return new soap_fault ('client', '', 'must supply a valid name .');
}
Return 'Hello! :, '. $ Name;
}
$ Http_raw_post_data = isset ($ http_raw_post_data )? $ Http_raw_post_data :'';
$ Server-> service ($ http_raw_post_data );
?>
After writing the server, you have to test it first. Visit the PHP page to see the following page:
Click "WSDL" to view the XML message defined in the WSDL"[Url] http://testweb.dev.php/testwebservice/testwebservice.php#/url]"/>[Url] URLs
Now I am writing a Java program to call WebService.
Example:
Package test;
Import javax. xml. rpc. serviceexception;
Import org. Apache. axis. Client. call;
Import org. Apache. axis. Client. Service;
Public class testwebservice {
Public static void main (string [] ARGs) throws exception {
// String endpoint = "http: // localhost: 8086/testwebservice/services/testwebservice ";
String endpoint = "http://testweb.dev.php/testWebService/testWebService.php"; // This section is the address just above
Service = new service ();
Call call = (CALL) service. createcall ();
Call. settargetendpointaddress (New java.net. URL (endpoint ));
Call. setoperationname ("hello ");
String Param = new string ("Chinese". getbytes (), "ISO-8859-1"); // if this section is not added, Chinese parameters will be garbled
String S = (string) Call. Invoke (new object [] {Param });
S = new string (S. getbytes ("ISO-8859-1"), "GBK"); // if there is no conversion encoding, Chinese characters will also be garbled
System. Out. println (s );
}
}
Nusoap. php defines the encoding var $ soap_defencoding = 'iso-8859-1 '. Therefore, I tried this encoding without generating Chinese garbled characters.