PHP5 Soap Call Implementation procedure, Php5soap call procedure _php Tutorial

Source: Internet
Author: User
Tags soap wsdl

PHP5 Soap Call Implementation procedure, Php5soap call procedure


In this paper, an example of the development of a company's iphone 6 mobile phone reservation interface is introduced, and the implementation process of soap call is PHP5.


First, the basic concept

Soap (Simple Object access Protocol) is a simple protocol for exchanging information in a decentralized or distributed environment, an XML-based protocol that consists of four parts: the SOAP Package (envelop), The wrapper defines a framework that describes what the content in the message is, who sent it, who should accept and handle it, and how to handle it; the SOAP encoding rule (encoding rules), which represents an instance of the data type that the application needs to use; SOAP RPC Representation (RPC representation), which represents the contract for remote procedure calls and replies; A SOAP binding (binding) that uses the underlying protocol to exchange information.

WSDL (Web service Description Language) is the standard XML format for describing XML Web services, and WSDL is presented by developers such as Ariba, Intel, IBM, and Microsoft. It defines the operations and messages sent and received by a given Web service in an abstract way that is not specific to the language. In its definition, you cannot consider WSDL as an Object interface definition language, for example, application architectures such as CORBA or COM use the Object interface definition language. WSDL maintains protocol neutrality, but it does have built-in support for binding soap, thus establishing an inextricable connection with soap. So, when I discuss WSDL in this article, I'll assume that you have soap as your communication protocol.

While soap and WSDL are two of the standards of Web service, they are not necessarily connected 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.


Second, the configuration under the PHP5

In the PHP configuration file php.ini, locate the

Extension=php_soap.dll

then remove the previous; Number and restart the Web service

Iii. querying Web service methods and parameters, data types

One province telecom Company's entry interface is HTTP://***.******.COM/SERVICES/ACCEPTEDBUSINESS?WSDL
We use SoapClient's __geunctions () and __gettypes () methods to view the interface's methods, parameters, and data types
Only the interfaces listed in __getfunctions can be called by soap.
Create code under the root directory soap.php

 
  PHPHeader("Content-type:text/html;charset=utf-8"); Try {    $clientnew soapclient ("http://***.******.com/services/acceptedbusiness?wsdl" );     Print_r ($client,__getfunctions ());     Print_r ($client,__gettypes ());   Catch $e {    print$e;}? >

After the browser runs: http://localhost/soap.php, the results are as follows

Array(    [0] = Arrayof_xsd_anytype introduceacceptedbusiness (string $c 3,string $c 4,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] = =stringIntroduceacceptedbusinessbycallout (string $xmlStr)    [4] = =stringINTRODUCEACCEPTEDBUSINESSBYYDDJ (string $xmlParam)    [5] = Arrayof_xsd_anytype Queryacceptedbusinessbyaizhuangwei (string $surveycode,string $starttime,string $endtime)    [6] = =stringQuerycalloutorderbyconfig (string $xmlParam))Array(    [0] = =AnyType arrayof_xsd_anytype[])

There is a method Introduceacceptedbusinessbystandardinterface (string $xmlStr) that will be the interface to be used in the development documentation, with the arguments as XML strings

There are other interfaces mentioned in the SoapHeader certification, which requires the addition of __setsoapheaders method, specific to see http://php.net/manual/zh/soapclient.setsoapheaders.php


Iv. Submission of orders

This step involves stitching the XML string according to the development document, and then passing in as a parameter to the Introduceacceptedbusinessbystandardinterface
Create a acceptedbusiness.php with the following content

 PhpHeader("Content-type:text/html;charset=utf-8");Try {    $client=NewSoapClient (' http://***.*******.com/services/acceptedbusiness?wsdl '); $xml= " 
    
    
    
     * *
     Telecom 
     
    
     Zhang San
     
    
     13412341234
     
    
     Guangdong Shenzhen
     
    
     ipho NE 6
     
     
    
     1111111111111111111111111111111
     2111 
    
     111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111
           
        
        
        
        
        
        
        
      
 
        
     
   "; $return=$client->introduceacceptedbusinessbystandardinterface ($xml); Print_r($return);} Catch(SoapFault$e) {    Print_r(' Exception: '.$e);}?>

After executing in the browser, return

  
   XML version= "1.0" encoding= "UTF-8" ?> <  Package >    < STATUS >0
   
     STATUS>    < REASON  > success in order! 
    
      REASON>    <orderseq> 2014100905523549742
     
       orderseq
      
         > Package >    


What is PHP WebService?

One of the advantages of soap compared to Nusoap is that it was developed in C and compiled into PHP's internal library of functions, and Nusoap is written entirely in PHP, and consists of a series of PHP classes. Advantage of the second, Nusoap is a long ago, from 2005-07-27 after the end of the update, and soap in the PHP5 version of the new, with PHP6 support for WebService, I believe that the role of SOAP library will continue to rise.

The PHP5 Soap library is easy to use, and WSDL can be generated using Zend development environment development tools.
Note a few questions:
1. To improve efficiency, PHP provides caching capabilities for WSDL files, which can be used when developing Ini_set ("soap.wsdl_cache_enabled", 0); To invalidate it because the development process often modifies the WSDL file;

2. SOAP (Simple Object access Protocol) provides a method addfunctions in that the PHP5 can not only provide object SetClass to remote access calls, but also to the protocol. So the ' O ' in soap has been expanded.

3. The server may not be able to access the client post data, which may be php5 soap functions bugs, the solution in the following server-side example program has a piece of code:
if (Isset ($HTTP _raw_post_data)) {
$request = $HTTP _raw_post_data;
} else {
$request = file_get_contents (' php://input ');
}
The following is an example of program source code.

Examples of SOAP clients:


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 );
}

?>

Soap Server-side examples:


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 ... Remaining full text >>

PHP calls the WebService function without soapclient what else is the method?

There are many types of webservice, and only soap-type webservice use SoapClient calls.

In fact, SoapClient is the encapsulation of the SOAP request. You can also use the underlying interface to access it, but this requires you to understand the SOAP protocol and is very cumbersome.

There is a library called Nusoap, which makes it easy to write SOAP services and SOAP requests, as you can see.

Hope to adopt, thank you for your support!

http://www.bkjia.com/PHPjc/894769.html www.bkjia.com true http://www.bkjia.com/PHPjc/894769.html techarticle PHP5 SOAP Call implementation process, Php5soap call procedure This paper introduces the implementation process of the SOAP call under PHP5, which is an example of the development of a company's iphone 6 mobile phone reservation interface. First, the basic concept of 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.