Example of SOAP usage in PHP, Phpsoap usage Example _php Tutorial

Source: Internet
Author: User
Tags wsdl

Examples of usages of soap in PHP, Phpsoap usages


The example of this article describes the use of soap in PHP, shared for everyone to reference. The specific usage analysis is as follows:

There are two ways in which PHP uses SOAP.

First, use the WSDL file

Server-side:

Copy CodeThe code is as follows: <?php
class Service
{
Public Function HelloWorld ()
{
return "Hello";
}
Public function Add ($a, $b)
{
return $a + $b;
}
}
$server =new soapserver (' soap.wsdl ', Array (' soap_version ' = soap_1_2));
$server->setclass ("service");
$server->handle ();
?>
A resource description file that can be generated using the tool (Zend Studio). is actually an XML file.
Copy CodeThe code is as follows: <?xml version= "1.0" encoding= "UTF-8"?>













































transport= "Http://schemas.xmlsoap.org/soap/http"/>




Namespace= "http://localhost/interface/"/>



Namespace= "http://localhost/interface/"/>









Client calls:
Copy CodeThe code is as follows: <?php
$soap = new SoapClient (' http://localhost/interface/soap.wsdl ');
echo $soap->add ();
?>
Two, no WSDL file

Server-side:

Copy the Code code as follows: <?php
class Service
{
Public Function HelloWorld ()
{
return "Hello";
}
Public function Add ($a, $b)
{
return $a + $b;
}
}
$server =new soapserver (null,array (' uri ' = ' abcd '));
$server->setclass ("service");
$server->handle ();
?>
Client:
Copy the Code code as follows: <?php
try{
$soap = new SoapClient (Null,array (
"Location" = "http://localhost/interface/soap.php",
"uri" = "ABCD",//Resource descriptor server and client must correspond to
"Style" = Soap_rpc,
"Use" = soap_encoded
));

echo $soap->add ();
}catch (Exction $e) {
Echo Print_r ($e->getmessage (), true);
}
?>

I hope this article is helpful to everyone's PHP programming.


PHP soap in Windows How to use (Phpini) are configured in the variable is also added is not allowed to use

How to determine that he can not use, no picture no truth can not determine the cause of the error (PHP5 above to support soap)

Example of implementing soap in PHP, such as a class file on a server, I can use from the exception of a server directly, example to the ocean,

try {

$this->soap-> = new SoapClient ("localhost/webservice.asmx?wsdl");//Note This is the ASMX service in C #.
$obj = $this->soap->webservice method Name (Array ("server parameter name" = "parameter Value", "second server parameter name" + "second parameter value"));
return $this->json_decode_csharp ($obj);//This is based on different service implementations of different parsing bodies (we are returning JSON data). Json_decode_csharp is my custom function
} catch (Exception $e) {
$this->file->vim ($e->__tostring (), $this->logpath. Date ("Ymd"). ". Log");
return null;
}
Can add PHP to learn the communication group in the group Q: 40383880

http://www.bkjia.com/PHPjc/899063.html www.bkjia.com true http://www.bkjia.com/PHPjc/899063.html techarticle The example of SOAP usage in PHP, Phpsoap Usage example, describes the use of soap in PHP, and shares it for everyone's reference. The specific usage analysis is as follows: PHP uses soap in two ways. ...

  • 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.