Implementing a simple Web services,soapservices_php tutorial with PHP SOAP extensions

Source: Internet
Author: User
Tags wsdl

Implement simple Web Services,soapservices with PHP SOAP extensions


What can webservices do?

WebServices can convert an application to a network application.

By using WebServices, your application can publish information to the world or provide a feature.

Well, about webservices online material many, not too much introduction, directly into the subject.

PHP has two extension class libraries can be implemented WebServices, one is Nusoap, one is the official PHP SOAP extension, in the use of roughly the same, take the official own SOAP extension.

The Soapclient,soapserver,soapfault three classes are used primarily in soap authoring webservices.

SoapClient: The class that the user accesses, that is, the client, using the WebServices class

SoapServer: Provide webservices class, service side

SoapFault: Exception Handling Class

As an example, write a super-simple webservices to feel it, direct code to speak

1, Myself.class.php--Business logic class, function realization class

 
 1 
   PHP2     // business logic classes 3class       myself{4          Public function info () {5             return "Sina Weibo: Balla_ Rabbit, seeking attention ~"; 6         }7    }8 ?>

It's easy to return a string without unnecessary explanation.

2, soapserver.php--Service End class, provide service

 
 1 
   PHP 2     // server 3     require_once(' Myself.class.php '); 4     $parameter=array(  5         ' uri ' = ' http://localhost/', 6         ' location ' = ' http://localhost/soap/soapServer.php ' 7        ); 8     $soapServer=new soapserver (null,$parameter); 9     $soapServer->setclass (' myself '); Ten     $soapServer-handle ();  ?>

The SoapServer has two modes of operation:

The above example is the non-wsdl mode , when instantiating the SoapServer class, a parameter is to put the WSDL file , in non-wsdl mode, can be empty, the configuration parameters in the form of an array in the second parameter .

If you are using wsdl mode , you can let the server read the configuration parameters directly with the WSDL file, and you can omit the second array parameter .

There are many configuration parameters, the above for a simple example only listed 2, specifically, we can check online

Uri--namespace

Location--Service address

1. wsdl mode in WSDL mode, the constructor can use the WSDL file name as a parameter and extract the information used by the service from the WSDL.

2. non-wsdl mode in non-wsdl mode, use parameters to pass the information to be used to manage the behavior of the service.

Among the many methods of the SoapServer class, there are three methods that are more important. They are soapserver::setclass (),soapserver::addfunction (),soapserver::handle ().

It is particularly important to note that no parameters can be output after the handle method, or an error occurs.

3, soapclient.php--client class, using the service

 
 1 
   PHP 2     // client 3     $parameter=array(  4          ' uri ' = ' http://localhost/', 5         ' location ' = ' http://localhost/soap/ Soapserver.php ' 6        ); 7     Try {  8         $soapClient=new soapclient (null,$parameter); 9         Echo $soapClient-info (); Ten One     } Catch (Exception$e) {         Echo $e-GetMessage ();  -     }?>

The SoapClient class can act as a client for a given webservices.
It has two modes of operation: (similar to the two models of SoapServer)
1. WSDL mode

2. NON-WSDL mode

These are simple webservices that are implemented with PHP SOAP extensions, and we visit soapclient.php to try

Easy to fix ~

Report:

Now the return value of most webservices interfaces is JSON or XML, and we can define our own assignments internally.

Common functions file_get_contents, Json_encode, Json_decode, etc.

Here's a note on JSON operations: http://www.cnblogs.com/lichenwei/p/3888586.html


How does php implement upload and download files through SOAP (Web Services)? -PHP Advanced Discussion title

Read the file in binary, and then pass him as an XML entity. View Original Posts >>

What is PHP soapclient?

Baike.baidu.com/view/2099744.htm

http://www.bkjia.com/PHPjc/859227.html www.bkjia.com true http://www.bkjia.com/PHPjc/859227.html techarticle what can webservices do with PHP SOAP extensions for simple Web services,soapservices? WebServices can convert an application to a network application. By using WebServices, your ...

  • Related Article

    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.