PHP 5 SOAP call implementation process, php5soap call process _ PHP Tutorial

Source: Internet
Author: User
Tags soap client
SOAP call implementation process in PHP5, and php5soap call process. SOAP call implementation process in PHP5. php5soap call process this article introduces the implementation process of SOAP call in PHP5 by taking the development of an iPhone 6 mobile phone booking interface in a company as an example. I. basic concepts SOAP (SOAP call implementation process under PHP5, php5soap call process

This article introduces the implementation process of SOAP calling in PHP5 by taking the iPhone 6 mobile phone reservation interface development of a company as an example.


I. Basic concepts

Simple Object Access Protocol (SOAP) is a Simple Protocol for exchanging information in a distributed or distributed environment. it is an XML-based Protocol that consists of four parts: the SOAP encapsulation (envelop) defines a framework that describes the content in a message, who sent the message, who should accept and process it, and how to process it; the SOAP encoding rules (encoding rules) are used to represent the data type instances required by the application; the soap rpc representation (RPC representation) indicates the protocols for remote process calls and responses; SOAP binding, which uses the underlying protocol to exchange information.

Web Service Description Language (WSDL) is the standard XML format used to describe XML Web services. WSDL is proposed by developers such as Arba, Intel, IBM, and Microsoft. It defines the operations and messages sent and received by a given Web service in an abstract way unrelated to a specific language. In terms of its definition, you cannot regard WSDL as an object interface definition language. for example, the application architecture such as CORBA or COM will use the object interface definition language. WSDL maintains protocol neutral, but it does have built-in support for binding SOAP, thus establishing an inseparable relationship with SOAP. So when I talk about WSDL in this article, I assume that you use SOAP as your communication protocol.

Although SOAP and WSDL are two standards of web services, they are not necessarily related and can be used independently. The relationship between them is similar to the relationship between HTTP and Html. The former is a protocol, and the latter is a description of a Web Server.


2. PHP5 configuration

In the php configuration file php. ini, find

extension=php_soap.dll

Remove the previous; number, and then restart the web service.

III. query web service methods, parameters, and data types

The incoming ticket interface of a provincial telecommunications company is http: // *****. *******. com/services/AcceptedBusiness? Wsdl
We use the _ geunctions () and _ getTypes () methods of SoapClient to view the methods, parameters, and data types of this interface.
Only interfaces listed in _ getFunctions can be called by soap.
Create code soap. php in the root directory

 __getFunctions());    print_r($client->__getTypes());  } catch (SOAPFault $e) {    print $e;}?>

After you run http: // localhost/soap. php in a browser, the following result is returned:

Array(    [0] => ArrayOf_xsd_anyType introduceAcceptedBusiness(string $c3, string $c4, string $linkman, string $linknum, string $num, string $idcard, string $remark, string $address)    [1] => ArrayOf_xsd_anyType introduceAcceptedBusinessByAiZhuangWei(string $subname, string $linkphone, string $idcard, string $address, string $businesstype, string $marketcode, string $surveycode, string $commanager, string $commanagerphone, string $bendiwang, string $fenju, string $zhiju, string $remark)    [2] => string introduceAcceptedBusinessByStandardInterface(string $xmlStr)    [3] => string introduceAcceptedBusinessByCallOut(string $xmlStr)    [4] => string introduceAcceptedBusinessByYddj(string $xmlParam)    [5] => ArrayOf_xsd_anyType queryAcceptedBusinessByAiZhuangWei(string $surveycode, string $starttime, string $endtime)    [6] => string queryCallOutOrderByConfig(string $xmlParam))Array(    [0] => anyType ArrayOf_xsd_anyType[])

There is a method introduceAcceptedBusinessByStandardInterface (string $ xmlStr), which will be the interface to be used in the development documentation. the parameter is an xml string.

In addition, some interfaces mentioned SoapHeader authentication, which requires the _ setSoapHeaders method, the specific can view the http://php.net/manual/zh/soapclient.setsoapheaders.php


4. submit an incoming ticket

This step is to concatenate an xml string according to the development document, and then pass it as the introduceacceptedbusinpolicystandardinterface parameter.
Create acceptedbusiness. php with the following content:

     
       
  
   
** China Telecom
        
        
  
   
Zhang San
        
  
   
13412341234
        
  
   
Guangdong, Shenzhen
        
  
   
IPhone 6
        
        
  
   
1111111111111111111111111111111
  2111      
  
   
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
      
 "; $ Return = $ client-> introduceAcceptedBusinessByStandardInterface ($ xml); print_r ($ return);} catch (SOAPFault $ e) {print_r ('exception :'. $ e) ;}?>

After Execution in the browser, return

 
     
  
   
0
      
  
   
Ticket entered!
      
  
   
2014100905523549742
  
 


What is php webservice?

Compared with nusoap, soap is developed and compiled into a php internal function library in c. NuSOAP is completely written in PHP and consists of a series of PHP classes. Advantage 2: nusoap was available a long time ago. it has stopped updating since, and Soap has been added to php5. with php6's support for webservice, I believe that the status of the function library soap will definitely grow.

The Soap function library of php5 is easy to use. wsdl can be generated using zend Development Environment Development tool.
Notes:
1. to improve efficiency, php provides the cache function for the wsdl file. during development, you can use ini_set ("soap. wsdl_cache_enabled ", 0); make it invalid because the wsdl file is frequently modified during development;

2. Simple Object Access Protocol (SOAP) Simple Object Access Protocol. in php5, you can not only provide the setClass Object for remote Access and call, but also provide the addFunctions method. Therefore, 'O' in SOAP has been extended.

3. the server may not be able to retrieve the data from the client POST, which may be the bugs of php5 soap functions. the solution is provided with a piece of code in the following server example program:
If (isset ($ HTTP_RAW_POST_DATA )){
$ Request = $ HTTP_RAW_POST_DATA;
} Else {
$ Request = file_get_contents ('php: // input ');
}
The following is the sample program source code.

Example of a soap client:


Ini_set ("soap. wsdl_cache_enabled", 0 );
Try {
$ Soap = new SoapClient ('authenticate/idolol. wsdl ');
$ Soap-> get_avatar (230 );
$ Functions = $ soap->__ getFunctions ();
Print_r ($ functions );
$ Types = $ soap->__ getTypes ();
Print_r ($ types );
} Catch (SoapFault $ fault ){
Trigger_error ("SOAP Fault: (faultcode: {$ fault-> faultcode}, faultstring: {$ fault-> faultstring})", E_USER_ERROR );
}

?>

Example of the soap server:


Require './soap_functions.php ';

Ini_set ("soap. wsdl_cache_enabled", 0 );

$ Server = new SoapServer ('authenticate/idolol. wsdl ', array ('encoding' => 'utf-8 '));
$ Server-> addFunction (array ("user_login", "se ...... full text >>
 

What other methods does php need to call the webservice function without SoapClient?

There are many types of webservices. only webservices of the SOAP type can be called using SoapClient.

In fact, SoapClient encapsulates soap requests. You can also use the underlying interface for access, but this requires you to understand the SOAP protocol and is very troublesome.

There is a library called nusoap that allows you to easily compile SOAP services and SOAP requests.

Thank you for your support!

This article introduces the implementation process of SOAP calling in PHP5 by taking the iPhone 6 mobile phone reservation interface development of a company as an example. I. basic concepts SOAP (...

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.