Implementing simple Web Services with a php SOAP extension

Source: Internet
Author: User
Tags array copy exception handling soap return web services client wsdl
What can webservices do?   WebServices can convert an application to a network application.   by using WebServices, your application can release information to the world or provide a feature.       Good, about webservices online data a lot, not too much introduced, directly into the subject.   PHP has two extended class libraries to implement WebServices, one is Nusoap, and the other is PHP's official SOAP extension, which is roughly the same in use, with the official SOAP extension.   Soapclient,soapserver,soapfault Three classes are used primarily in soap authoring webservices.   soapclient: User-accessed classes, i.e. clients, using WebServices classes   SoapServer: Providing WebServices class, service-side   SoapFault: Exception handling class       As an example, write a super simple webservices to feel it, direct code talk       1, Myself.class.php--Business logic class, function implementation class   copy code 1 &L t;? PHP 2    //Business logic Class 3     class myself{4         Public Function info () {5   & nbsp         return "Sina Weibo: Balla_ Rabbit, ask for attention ~"; 6         {7    } 8?> The copy code is simple and requires no extra explanation to return a string.       2, soapserver.php--service-side class, providing services   copy code  1 <?php  2    //service side  3     require_once (' Myself.class.php ');   4     $parameter =array ( 5         ' uri ' => ' http://localhost/',  6   &nbsp ;     ' location ' => ' http://localhost/soap/soapServer.php '  7        ;  8     $soapServer =new soapserver (null, $parameter);  9     $soapServer->setclass (' myself ');     $soapServer->handle (); One?> copy code SoapServer There are two modes of operation:   The above example is the NON-WSDL mode, in the instantiation of the SoapServer class, a parameter is a WSDL file, in the NON-WSDL mode, can be empty, The configuration parameters are written in the form of an array in the second parameter.   If you are using WSDL mode, you can have the server read the configuration parameters directly with the WSDL file, and you can omit the second array parameter.   Configuration parameters are many, above for a simple example to List 2, specifically you can check the Internet   URI--namespace   location--service address   1, WSDL mode in WSDL mode, the constructor can use the WSDL file Name as a parameter and extracts the information used by the service from the WSDL.   2, non-wsdl mode in non-wsdl mode, use parameters to pass the information to use to manage the behavior of the service.       Among the many methods of SoapServer class, three methods are more important. They are Soapserver::setclass (), Soapserver::addfunction (), Soapserver::handle ().     Pay special attention to the inability to output any parameters after the handle method, or there will be an error.       3, soapclient.php--GuestUser-side classes, using services   replication code  1 <?php  2    //client  3     $parameter =array ( 4   & nbsp     ' uri ' => ' http://localhost/',  5      -  ' location ' => ' Http://localhost/soap /soapserver.php '  6        );  7     try{ 8         $soapClient =new soapclient (null, $parameter);  9         echo $soapClient->info (); 10     }catch (Exception $e) {$e         echo->getmessage ()     14 ?> Copy Code SoapClient class can serve as the client for a given webservices.

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.