We can see that it is very easy to use this method to create a soap based on wsdl verification, but there is a problem that requires attention. Because php is a weak type language (it does not mean that it has weak functions, but php has weak control over data types), the data type of the wsdl parameter is string.
Today, we will discuss several topics related to the use of soap in php.
First, let's talk about the wsdl issue. In soap, wsdl is used to declare methods in web service and regulate the number and data type of entry and exit parameters of methods.
Most php programmers may not write the wsdl manually. in this case, we can use a third-party class library: SoapDiscovery. class. php. Below are examples: ========================================================== ==============================================
Step 1: Write server. php. the content is the method provided by your soap server. Write_log ($ select_ SQL, $ this-> log_file); return $ select_ SQL;}/** function: write logs * $ file_name: log file name * $ string: log content */private function write_log ($ string, $ file_name) {date_default_timezone_set ("Asia/Shanghai"); $ now_time = date ("Y-m-d H: m: s "); $ file_resource = fopen ($ file_name, 'A'); fwrite ($ file_resource, $ now_time. '= '. $ string. "\ r \ n"); fclose ($ file_resource) ;}}?> ========================================================== ==============================================
Step 2: write creat_wsdl.php. the function of this file is to automatically generate the wsdl for you. GetWSDL ();?> ========================================================== ==============================================
Step 3: execute creat_wsdl.php to automatically generate the wsdl. After Execution, a Service. wsdl will appear in the current directory. It is the wsdl automatically generated according to the Service method. ========================================================== ==============================================
Step 4: modify server. php and use php's soap extension to make it a soap server Write_log ($ select_ SQL, $ this-> log_file); return $ select_ SQL;}/** function: write logs * $ file_name: log file name * $ string: log content */private function write_log ($ string, $ file_name) {date_default_timezone_set ("Asia/Shanghai"); $ now_time = date ("Y-m-d H: m: s "); $ file_resource = fopen ($ file_name, 'A'); fwrite ($ file_resource, $ now_time. '= '. $ string. "\ r \ n"); fclose ($ file_resource) ;}// generate the soap server $ server = new SoapServer ('service. wsdl ', array ('So Ap_version '=> SOAP_1_2); $ server-> setClass ("Service"); // register all methods of the Service class $ server-> handle (); // process the request?> ========================================================== ==============================================
Step 5: write client. php, which is a soap client request _ SoapCall ('start _ dk ', array (1, 2); echo $ soap_return;?> ========================================================== ==============================================
NoteWe can see that it is very easy to use this method to create a soap based on wsdl verification, but there is a problem that requires attention. Because php is a weak type language (not to mention its weak function, but php has weak control over data types), the data type of the wsdl parameter is string. If you want to have special control over data types, you can modify the wsdl based on the automatic generation of third-party class libraries.