通俗语言说 SOA SOAP WSDL REST

SOA

SOA:(面向服务的架构 Service-Oriented Architecture) 就是说此类架构是面向服务的。原理是抽象底层的复杂关系,使用户可以简单调用接口服务。

下面讲到的 SOAP RPC 等都是 SOA 的一种实现而已。

非 WSDL 的 SOAP

// test.php  原始脚本
class ServiceFunction
{
    public function getDisplayName($firstName, $lastName)
    {
        $name = strtoupper(substr($firstName, 0, 1)) . " " . ucfirst($lastName);
        return $name;
    }
}

$options = [
    "uri" => "http://localhost/",
];
$server = new SoapServer(NULL, $options);
$server->setClass("ServiceFunction");
$server->handle();


// tmp.php  调用脚本
$options = [
    "uri" => "http://localhost/",
    "location" => "http://localhost/b/test.php",
    "trace" => 1
];
$client = new SoapClient(NULL, $options);
echo $client->getDisplayName("michael", "leon");


# 输出: M Leon
/*
SOAP :Simple Object Access Protocol 简单对象访问协议
WSDL (web service description language): 用来描述 web 服务的一组定义。 本来 soap 就比较复杂,用的人较少。现在与 WSDL 结合将更加复杂。这里就不再举例。详情百度。
*/

RPC

RPC : Remote Procedure Call Protocol 远程程序调用协议
SOAP 是一种特殊的 xml-RPC。个人理解,SOAP 是类的远程调用。而 RPC 是方法或函数的远程调用。

require "Service.class.php";
if(isset($_GET["method"])){
    switch($_GET["method"]){
        case "countWords":
            $response=Service::countWords($_GET["words"]);
        break;
            case "getDisplayName":
            // ...

    }
}
header("Content-Type:application/json");
echo json_encode($response);

// 调用脚本
GET http://foo.foo?words=michael

REST

REST : Representational State Transfer 表述性状态转移
性能、效率和易用性上都优于SOAP协议。
REST架构对资源的操作包括获取、创建、修改和删除资源的操作正好对应HTTP协议提供的GET、POST、PUT和DELETE方法(Verb)。

$request=new Request();
$request->urlElements=[];
if(isset($_SERVER['PATH_INFO'])){
    $request->urlElements=explode('/',$_SERVER['PATH_INFO']);
}
switch($_SERVER['REQUEST_METHOD']){
    case "GET":
        ...
    break;
    case "POST":
        ...
    break;
    case "PUT":
        ...
    break;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值