Create Oracle-driven SOAP service using PHP (1) _ PHP Tutorial

Source: Internet
Author: User
Use PHP to create an Oracle-driven SOAP service (1 ). The ability to provide data and functions for other Internet-based Web applications through Web services is rapidly becoming an indispensable part of major development. Although Oracle provides a lot of data and functionality that can be provided to other Internet-based Web applications through Web services, it is quickly becoming an indispensable part of major development. Although Oracle provides many ways to host Web services, this is never the most effective method, especially when PHP is used to develop Web applications. In this manual, I will guide you through using PHP to gradually develop SOAP clients and servers, and use Oracle as the data backend.

To really understand the answer to this question, you need to understand the lifecycle of PHP script execution and the impact of Web servers on this lifecycle. This manual will start from then on.

Required components

For the purpose of this article, you will use a very simple database backend that stores some basic information about published books in a table, which is represented by the following CREATE statement:

CREATE TABLE books(isbn VARCHAR(32) PRIMARY KEY,author VARCHAR(50),title VARCHAR(50),price FLOAT);

The table serves as the data source of the SOAP server, and the data source provides the data to one or more SOAP clients as needed. Although your database may be complex in actual applications, the method described here still applies.

After you create a database (preferably place some virtual data in it), you can now get a deeper understanding of the content involved in developing a SOAP server using PHP.

How the SOAP service works in PHP

There are multiple options for developing SOAP services using PHP. all methods involve the SoapServer PHP class. This class is the core part of all PHP-based SOAP services. Its syntax is as follows:

$server = new SoapServer($wsdl [, $options]);

$ Wsdl is the location of the Web service description Language (WSDL) document describing the managed service; $ options is a set of key/value pairs, it includes all the settings that need to be considered when creating a service. Later, you will learn more about the WSDL document. now, let's take a look at the options available when creating a new SOAP service:

◆ Soap_version: The SOAP protocol version used for communication with the client. Possible options are the constant SOAP_1_1 for SOAP 1.1 or SOAP_1_2 for SOAP 1.2.

◆ Encoding: Character encoding (character string ISO-8859-1) used for the SOAP service ).

◆ Actor: role URI of the SOAP service.

◆ Classmap: map the WSDL data type to a group of key/value pairs of class names in PHP. If this option is used, PHP presents these classes to the connection client based on the types defined in the WSDL.

Therefore, to create a SOAP service using the SOAP v1.2 protocol using the wsdl file named bookman. WSDL, you should build the server as follows:

$server = new SoapServer(“bookman.wsdl”, array(‘soap_version’ => SOAP_1_2));

The next step in this process is to create a service method. In PHP, this can be done using two main methods. The first (and most flexible) method is to manually specify each function to be hosted in the service using the addFunction () method, and pass the function name to this method to make it public to the client:

function add($a, $b) {return $a + $b;}$server->addFunction(‘add’);

You can also add multiple functions by providing a group of function names:

function add($a, $b) {return $a + $b;}function sub($a, $b) {return $a - $b;}$server->addFunction(array(‘add’, ‘sub’));

Finally, you can export all the defined functions by passing the special constant SOAP_FUNCTIONS_ALL instead of the function name, as shown below:

function add($a, $b) {return $a + $b;}function sub($a, $b) {return $a - $b;}$server->addFunction(SOAP_FUNCTIONS_ALL);

1

The middleware Web service provides data and functions for other Internet-based Web applications, which is becoming an indispensable part of major development. Although Oracle provides many support...

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.