Home > Article > Backend Development > Example of creating and calling webservice interface in php, webservice example_PHP tutorial
As a developer, if you want to write a webservice interface or call someone else's webservice interface, you first need to understand what a webservice is. To put it simply, WebService is a service opened by some sites, or it can be a Service developed by you, that is, some methods. Through the URL, you specify a method name and make a request. The service (method) in the site will receive your request. The request will do some processing based on the passed parameters, and then return the processed results to you in XML form. Your program will parse the XML data and then display it or perform other operations.
You need to understand when writing webservices: the basic Web Services platform is XML + HTTP; in addition, the elements of the Web services platform: SOAP (Simple Object Access Protocol), UDDI (Universal Description, Discovery and Integration), WSDL (Web Services Description Language) ; Any webservice includes client and server. The following uses an example to explain how to use PHP to write a webservice interface for others to call:
First you need to create a .wsdl file, so how to create this file in PHP. There are two ways to achieve this, one is to generate it directly using the zend studio tool; the other is to use PHP to automatically generate a wsdl file based on SoapDiscovery.class.php; which one you choose depends on your own situation. I generally use the former. fast. Let’s write down how to generate a wsdl file using a class. First, you need to download the class file from the Internet, and then after importing the class file, look at the following code:
creat_wsdl.php
After writing the server and wsdl files, you need to call them from the client. Please see the client calling code:
client.php
This is a complete example code for writing webservice interface and calling, I hope it will be helpful to those who need phper;
Then calling someone else's webservice interface is the code written in client.php.
Use soapclient, it’s not difficult. If you are using Java, it should be no problem! If you have any questions, please contact us in detail!
The interface can be called directly; it is best to have an interface description. Parameter type is the key