当前位置:网站首页>PHP5下WSDL,SOAP调用实现过程
PHP5下WSDL,SOAP调用实现过程
2022-07-05 13:53:00 【星哥玩云】
一、基础概念
SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协议,它包括四个部分:SOAP封装(envelop),封装定义 了一个描述消息中的内容是什么,是谁发送的,谁应当接受并处理它以及如何处理它们的框架;SOAP编码规则(encoding rules),用于表示应用程序需要使用的数据类型的实例; SOAP RPC表示(RPC representation),表示远程过程调用和应答的协定;SOAP绑定(binding),使用底层协议交换信息。
WSDL(Web Service Description Language)就是描述XML Web服务的标准XML格式,WSDL由Ariba、Intel、IBM和微软等开发商提出。它用一种和具体语言无关的抽象方式定义了给定Web服务收发 的有关操作和消息。就其定义来说,你还不能把WSDL当作一种对象接口定义语言,例如,CORBA或COM等应用程序体系结构就会用到对象接口定义语言。 WSDL保持协议中立,但它确实内建了绑定SOAP的支持,从而同SOAP建立了不可分割的联系。所以,当我在这篇文章中讨论WSDL的时候,我会假定你 把SOAP作为了你的通讯协议。
SOAP和WSDL虽然是web service的两大标准,但是两者并没有必然的联系,都可以独立使用。它们之间的关系就类似HTTP和Html之间的关系。前者是一种协议,后者是对一个Web Server的描述。
二、PHP5下的配置
在php的的配置文件php.ini中,找到
extension=php_soap.dll
然后将前面的;号去掉,然后重启web服务
三、查询web service方法与参数、数据类型
某省电信公司的入单接口为http://***.******.com/services/AcceptedBusiness?wsdl 我们使用SoapClient的__geunctions()和__getTypes()方法查看该接口的方法,参数和数据类型 只有__getFunctions中列出的接口才能被soap调用。 在根目录下创建代码soap.php
<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient("http://***.******.com/services/AcceptedBusiness?wsdl");
print_r($client->__getFunctions());
print_r($client->__getTypes());
} catch (SOAPFault $e) {
print $e;
}
?>
在浏览器运行:http://localhost/soap.php后,返回结果如下
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[]
)
其中有个方法 introduceAcceptedBusinessByStandardInterface(string $xmlStr),将是开发文档中提到的要使用的接口,参数为xml字符串
另外有的接口中提到有SoapHeader认证,这就需要加入__setSoapHeaders方法,具体可查看http://php.net/manual/zh/soapclient.setsoapheaders.php
四、提交入单
这一步就是需要根据开发文档拼接xml字符串,然后作为introduceAcceptedBusinessByStandardInterface的参数传入 创建acceptedbusiness.php,内容如下
<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient('http://***.*******.com/services/AcceptedBusiness?wsdl');
$xml = "
<?xml version='1.0' encoding='UTF-8' ?>
<PACKAGE>
<C3>**电信</C3>
<C4></C4>
<LINKMAN>张三</LINKMAN>
<LINKNUM>13412341234</LINKNUM>
<LINKADDRESS>广东深圳</LINKADDRESS>
<REMARK>iPhone 6</REMARK>
<CHANNEL></CHANNEL>
<GRIDCODE>1111111111111111111111111111111</GRIDCODE>
<AGENTCODE>2111</AGENTCODE>
<KEY>1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111</KEY>
</PACKAGE>
";
$return = $client->introduceAcceptedBusinessByStandardInterface($xml);
print_r($return);
} catch (SOAPFault $e) {
print_r('Exception:'.$e);
}
?>
在浏览器中执行后,返回
<?xml version="1.0" encoding="UTF-8"?>
<PACKAGE>
<STATUS>0</STATUS>
<REASON>入单成功!</REASON>
<ORDERSEQ>2014100905523549742</ORDERSEQ>
</PACKAGE>
边栏推荐
- 【云资源】云资源安全管理用什么软件好?为什么?
- In addition to the root directory, other routes of laravel + xampp are 404 solutions
- redis6主从复制及集群
- JS takes key and value from an array object to form a new object
- Godson 2nd generation burn PMON and reload system
- Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
- 基于微信小程序的订餐系统
- 2022建筑焊工(建筑特殊工种)特种作业证考试题库及在线模拟考试
- Requset + BS4 crawling shell listings
- Elk enterprise log analysis system
猜你喜欢
IP packet header analysis and static routing
锚点导航小demo
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
清大科越冲刺科创板:年营收2亿 拟募资7.5亿
redis6事务和锁机制
What happened to the communication industry in the first half of this year?
[cloud resources] what software is good for cloud resource security management? Why?
jasypt配置文件加密|快速入门|实战
Rk3566 add LED
随机推荐
Matlab learning 2022.7.4
OSI and tcp/ip protocol cluster
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
Network security - Novice introduction
Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
Ueditor + PHP enables Alibaba cloud OSS upload
蓝桥杯学习2022.7.5(上午)
这18个网站能让你的页面背景炫酷起来
2022 construction welder (special type of construction work) special operation certificate examination question bank and online simulation examination
Zhubo Huangyu: it's really bad not to understand these gold frying skills
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
Leetcode array question brushing notes
Zhubo Huangyu: these spot gold investment skills are not really bad
NFT value and white paper acquisition
【华南理工大学】考研初试复试资料分享
asp. Net read TXT file
kafaka 日志收集
::ffff:192.168.31.101 是一个什么地址?
These 18 websites can make your page background cool
[South China University of technology] information sharing of postgraduate entrance examination and re examination