Use the php third-party class library to automatically generate the wsdl

Source: Internet
Author: User
Tags soap client
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.

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.