Soap is based on XML and HTTP communication protocols. The way to use soap in php is to add the soap module of php, that is, add "soap.so" to php.ini.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
1. What does php soap mean? What are wsdl and why should we use them?
SOAP is based on XML and HTTP communication protocols, and is supported by various xml platforms and languages. http is supported by all Internet browsers and servers.
WSDL refers to Web Services Description Language (Web Services Description Language), which is a document written in XML. This document describes a Web service. It specifies the location of the service and the operations provided by this service.
I work in PHP, you work in Java, and he works in .NET. What if the three of us want to communicate and exchange data? We need a tool that can communicate with us all. soap, wsdl were created so that applications running on different operating systems and using different technologies and programming languages can communicate with each other.
2. Example
If PHP wants to use soap, the usual method is to add the soap module of PHP and add soap.so in php.ini , here is a method to implement soap
//包函nusoap.php require_once('./lib/nusoap.php'); //创建服务端 $server=newsoap_server; //定义客户端调用方法 $server->register('hello'); //调用方法以及参数 functionhello($name) { return'Hello, '.$name; } $HTTP_RAW_POST_DATA= isset($HTTP_RAW_POST_DATA) ?$HTTP_RAW_POST_DATA:''; $server->service($HTTP_RAW_POST_DATA); ?>
p without adding soap.so file
nusoap is a functional file written in PHP, you can use it if you include it. There are a lot of them online, so search them out yourself.
1. Do not use wsdl
a. Server helloworld2.php
b. Client hello.php
//包函nusoap.php require_once('./lib/nusoap.php'); //新建一个soap客户端,调用服务端提供的wsdl //$client = new soapclient('http://localhost/test/hellowsdl2.php?wsdl', true); $client=newsoapclient('http://localhost/test/helloworld2.php'); //查看一下是不是报错 $err=$client->getError(); if($err) { //显示错误 echo' Constructor error '.$err.' '; } //调用服务端的方法 $result=$client->call('hello',array('person'=>"this is a test")); echo' Result '; print_r($result); echo' '; ?>
2. Use wsld
a, Server side
//包函nusoap.php require_once('./lib/nusoap.php'); //新建一个soap服务 $server=newsoap_server(); //初始化支持wsdl $server->configureWSDL('hellowsdl2','urn:hellowsdl2'); //定义数据结构来接收数据 $server->wsdl->addComplexType( 'Person', 'complexType', 'struct', 'all', '', array( 'firstname'=>array('name'=>'firstname','type'=>'xsd:string'),//后面的type定义数据的类型,这个是string 'age'=>array('name'=>'age','type'=>'xsd:int'),//后面的type定义数据的类型,这个是int 'gender'=>array('name'=>'gender','type'=>'xsd:string')//后面的type定义数据的类型,这个是string ) ); $server->wsdl->addComplexType( 'SweepstakesGreeting', 'complexType', 'struct', 'all', '', array( 'greeting'=>array('name'=>'greeting','type'=>'xsd:string'), 'winner'=>array('name'=>'winner','type'=>'xsd:string') ) ); //服务器定义的soap调用方法 $server->register('hello',// 方法名字hello,方法就在下面 array('person'=>'tns:Person'),// 客户端传来的变量 array('return'=>'tns:SweepstakesGreeting'),//返回参数 'urn:hellowsdl2',// soap名 'urn:hellowsdl2#hello',// soap的方法名 'rpc',// 使用的方式 'encoded',// 编码 'test'// 存档 ); //定义上面注册过的函数hello functionhello($person) { $greeting='Hello, '.$person['firstname'].'. It is nice to meet a '.$person['age'].' year old '.$person['gender'].'.'; $winner='Scott'; //要返回的数据 returnarray( 'greeting'=>$greeting, 'winner'=>$winner ); } // 请求时(试图)调用服务 $HTTP_RAW_POST_DATA= isset($HTTP_RAW_POST_DATA) ?$HTTP_RAW_POST_DATA:''; $server->service($HTTP_RAW_POST_DATA); ?>
b, Client side
//包函nusoap.php require_once('./lib/nusoap.php'); //新建一个soap客户端,调用服务端提供的wsdl //$client = new soapclient('http://localhost/test/hellowsdl2.php?wsdl', true); $client = new soapclient('http://localhost/test/helloworld2.php'); //查看一下是不是报错 $err = $client->getError(); if ($err) { //显示错误 echo ' Constructor error ' . $err . ' '; } //要向服务端要传的参数 $person = array('firstname' => 'Willi', 'age' => 22, 'gender' => 'male'); //调用服务端的方法 $result = $client->call('hello', array('person' => $person)); //错误审核 if ($client->fault) { echo ' Fault '; print_r($result); echo ' '; } else { $err = $client->getError(); if ($err) { echo ' Error ' . $err . ' '; } else { echo ' Result '; print_r($result); echo ' '; } } //显示请求信息 echo ' Request '; echo ' ' . htmlspecialchars($client->request, ENT_QUOTES) . ' '; //显示返回信息 echo ' Response '; echo ' ' . htmlspecialchars($client->response, ENT_QUOTES) . ' '; //显示调试信息 echo ' Debug '; echo ' ' . htmlspecialchars($client->debug_str, ENT_QUOTES) . ' '; ?>
The above two examples, whether client or server, are written in PHP. You can try to use Write it in multiple languages to test it out. Regardless of whether you are using PHP modules or nusoap, I won’t go into details about the specific methods here, they are all in the manual.
SOAP does not need to be introduced here. Here is just a simple example of implementing SOAP. Not much to say, let’s look at the code. Soap is divided into server and client. We need to make the client call the server's code. First, look at the short code of the server:
This is the server-side code: server.php
<?php //声明一个函数add() ,并返回它的值 function add($a,$b){ return $a+$b; } //实例化一个SoapServer对象, 并将add函数注册成为其方法 $server = new SoapServer(null,array('uri'=>'http://localhost/')); //指定server端代码的URI(资源标志符) $server->addFunction("add"); $server->handle();?>
Then use the client-side code Code to call the server-side code: The client code is also very simple: as follows:
This is the client-side code client.php
<?php //建立一个参数数组,存储要访问的提供soap服务的计算机的地址与程序 $arrOptions=array( 'uri'=>'http://localhost/', 'location'=>'http://localhost/soap/server.php', //注意: 这个location指定的是server端代码在服务器中的具体位置, 我的是在本地根目录下的soap目录中, 'trace'=>true, ); $soapObject = new SoapClient(null,$arrOptions); //实例化客户端对象 echo $soapObject->add(20,30); //调用服务器端的函数add并返回值50?>
ok, it’s over!
Recommended learning : "PHP Video Tutorial"
The above is the detailed content of What does php soap mean?. For more information, please follow other related articles on the PHP Chinese website!

在Web开发领域中,Web服务是一种非常重要的技术,它可以使不同的应用程序之间互相通信,从而构建更加复杂和强大的系统。在本文中,我们将深入探讨如何使用PHP和SOAP实现Web服务的调用和开发。SOAP(SimpleObjectAccessProtocol)是一种基于XML的协议,它用于在不同的应用程序之间进行信息交换。SOAP是一个重要的Web服务标

PHP和SOAP:如何实现远程过程调用(RPC)简介:近年来,随着分布式系统的兴起,远程过程调用(RemoteProcedureCall,RPC)在Web开发中被广泛采用。本文将介绍如何使用PHP和SOAP实现RPC,以及通过代码示例演示其用法。一、什么是远程过程调用(RPC)?远程过程调用(RemoteProcedureCall,RPC)是一种通信

PHP和SOAP:如何实现数据的同步和异步处理引言:在现代Web应用程序中,数据的同步和异步处理变得越来越重要。同步处理指的是一次只处理一个请求,并等待该请求完成后再处理下一个请求;而异步处理则是同时处理多个请求,并不等待某个请求的完成。在本文中,我们将介绍如何使用PHP和SOAP来实现数据的同步和异步处理。一、SOAP简介SOAP(SimpleObjec

随着互联网技术的不断发展,越来越多的企业级应用需要向其它应用程序提供接口以实现数据和业务的交互。在这种情况下,我们需要一种可靠的协议来传输数据并确保数据的完整性和安全性。SOAP(SimpleObjectAccessProtocol)就是一种基于XML的协议,可用于在Web环境中实现应用之间的通信。而PHP作为一种流行的Web编程语言,

如何使用PHP和SOAP实现数据的压缩和解压缩导言:在现代互联网应用中,数据的传输是非常常见的操作,然而,随着互联网应用的不断发展,数据量的增加和传输速度的要求,合理地使用数据压缩和解压缩技术成为了一个非常重要的话题。在PHP开发中,我们可以使用SOAP(SimpleObjectAccessProtocol)协议来实现数据的压缩和解压缩。本文将介绍如何

如何使用PHP和SOAP实现Web服务的部署和发布引言:在当今互联网时代,Web服务的部署和发布成为了一个非常重要的话题。PHP是一种流行的服务器端编程语言,而SOAP(SimpleObjectAccessProtocol)是一种XML协议,用于在Web服务之间进行通信。本文将向您介绍如何使用PHP和SOAP实现Web服务的部署和发布,并提供一些代码示

利用PHP和SOAP构建基于Web的应用程序的完整指南在当今互联网的时代,基于Web的应用程序已经成为了管理和交互数据的重要工具。PHP作为一种强大的开发语言,可以与其他技术进行无缝集成,而SOAP(SimpleObjectAccessProtocol)作为一种基于XML的通信协议,为我们提供了一种简单、标准和可扩展的方法来构建Web服务。本文将为您提

在实际成功渗透过程中,漏洞的利用都是多个技术的融合,最新技术的实践,本次渗透利用sqlmap来确认注入点,通过sqlmap来获取webshell,结合msf来进行ms16-075的提权,最终获取了目标服务器的系统权限。本文算是漏洞利用的一个新的拓展,在常规Nday提权不成功的情况下,结合msf进行ms16-075成功提权的一个经典案例。1.1.1扫描soap注入漏洞1.使用awvs中的webservicesscanner进行漏洞扫描打开awvs,选择webservicesscanner进行漏洞扫


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
