WebService SOAP WSDL UDDI 使用php的curl、PHP5的SoapClient实现同步
一、基本名词
WebService:
WebService是一种跨编程语言和跨操作系统平台的远程调用技术。不同系统,不同语言的数据交换方法都是不同的,这就导致在不同系统,不同语言之间传递数据很麻烦,基于此,WebService出现了。SOAP、WSDL和UDDI构成WebService平台的基础。
SOAP(Simple Object Access Protocol):
要想传递数据,首先我们要统一数据的格式,这样大家按照同一个规范了才能保证数据格式统一,不会错乱。SOAP是基于xml定义的轻量级协议。
WSDL(Web Services Description Language):
WSDL文件用于告诉使用者数据的具体格式、数据参数、服务地址、可用函数等,解析wsdl文件就知道对方提供的服务内容。推荐软件soapui解析wsdl文件。
UDDI(Universal Description, Discovery and Integration):
统一描述、发现和集成,用于集中存放和查找WSDL描述文件,起着目录服务器,分享服务的作用。
虽然都是一些新的概念,但其实WebService都是基于一些旧有的技术,所以当了解原理后,就可以用原有的技术实现同样的功能。
二、php实现同步
由于这部分只涉及到同步,所有使用curl就能完成。以下就是代码:
只需要在http的头域中添加相应的方法,并用xml传递数据。依照同理,其他语言同样可以实现。关于方法和xml格式建议使用soapui解析wsdl文件获得。


private function http_request_xml($url,$data = null,$arr_header = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
// curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
if(!empty($arr_header)){
curl_setopt($curl, CURLOPT_HTTPHEADER, $arr_header);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
$xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:app=\"http://siebel.com/Voucher/Apply\">
<soapenv:Header/>
<soapenv:Body>
<app:VoucherApply_Input>
<app:count>1</app:count>
<app:memberNumber>".$mem."</app:memberNumber>
</app:VoucherApply_Input>
</soapenv:Body>
</soapenv:Envelope>";
$arr_header[] = "Content-type: text/xml"; //使用xml格式传递
$arr_header[] = "SOAPAction:\"document/http://siebel.com/Voucher/Apply:VoucherApply\""; //添加swdl的方法
$res = $this->http_request_xml($url, $xml, $arr_header);
if(strstr($res,"<ns:flag>S</ns:flag>")){
}
PHP5下方法
1、在php的的配置文件php.ini中,找到
extension=php_soap.dll
去掉;号,重启。
2、获取方法和参数:
<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient("http://***.******.com/services?wsdl");
print_r($client->__getFunctions());
print_r($client->__getTypes());
} catch (SOAPFault $e) {
print $e;
}
?>
3、带参数访问:
<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient('http://***.*******.com/services?wsdl');
$xml = "<?xml version='1.0' encoding='UTF-8' ?>";
$return = $client->function($xml);
print_r($res);
} catch (SOAPFault $e) {
print_r('Exception:'.$e);
}
?>
三、WSDL详解
直接打开wsdl文件如下:
<?xml version="1.0" encoding="utf-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsdLocal1="http://www.siebel.com/xml/TESITOSynTxn" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://siebel.com/Transaction" targetNamespace="http://siebel.com/Transaction"> // 所有的WSDL文档的根元素均是definitions元素。该元素封装了整个文档。
<types> // web service使用的数据类型,types元素用作一个容器,用于定义XML模式内置类型中没有描述的各种数据类型。
<xsd:schema elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://www.siebel.com/xml/TESITOSynTxn"> // xsd根元素
<xsd:annotation>
<xsd:documentation>Copyright (C) 2001-2004</xsd:documentation>
</xsd:annotation>
<xsd:element name="ListOfLoyTransaction" type="xsdLocal1:ListOfLoyTransaction"/> //定义一个数据类型 <xsd:complexType name="ListOfLoyTransactionTopElmt">
<xsd:sequence>
<xsd:element name="ListOfLoyTransaction" maxOccurs="1" minOccurs="1" type="xsdLocal1:ListOfLoyTransaction"/> //定义一个子数据类型
</xsd:sequence>
</xsd:complexType> <xsd:complexType name="ListOfLoyTransaction">
<xsd:sequence>
<xsd:element name="Transaction" maxOccurs="unbounded" minOccurs="0" type="xsdLocal1:LOYTransaction"/>
</xsd:sequence>
</xsd:complexType> <xsd:complexType name="Transaction"> // 父元素
<xsd:sequence> // 表示子元素依次出现顺序
<xsd:element name="RedMark" maxOccurs="1" minOccurs="0" type="xsd:string"/> // maxOccurs最多数量 minOccurs最少数量,实现参数的可选
<xsd:element name="ProdCode" maxOccurs="1" minOccurs="0" type="xsd:string"/>
<xsd:element name="OrderType" maxOccurs="1" minOccurs="0" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType> </xsd:schema> <xsd:schema elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://siebel.com/Transaction">
<xsd:import namespace="http://www.siebel.com/xml/SynTxn"/> // import元素使得可以在当前的WSDL文档中使用其他WSDL文档中指定的命名空间中的定义元素。 <xsd:element name="Txn_Input">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="xsdLocal1:ListOfLoyTransaction"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element> <xsd:element name="Txn_Output">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ErrorFlag" type="xsd:string"/>
<xsd:element name="ErrorMessage" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element> </xsd:schema>
</types> <message name="Txn_Input"> //web service 使用的消息
<part name="Txn_Input" element="tns:Txn_Input"/>
</message>
<message name="Txn_Output"> //web service 使用的消息
<part name="Txn_Output" element="tns:Txn_Output"/>
</message> <portType name="spcSyn_spcTransaction_spcWorkflow"> // portType元素定义了Web服务的抽象接口。portType元素是由binding和service元素来实现的,
<operation name="Txn">
<input message="tns:Txn_Input"/>
<output message="tns:Txn_Output"/>
</operation>
</portType> <binding name="spcSyn_spcTransaction_spcWorkflow" type="tns:spcSyn_spcTransaction_spcWorkflow"> //web service 使用的通信协议,将一个抽象portType映射到一组具体协议(SOAO和HTTP)、消息传递样式、编码样式。
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="Txn">
<soap:operation soapAction="document/http://siebel.com/Transaction:Txn"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding> <service name="SynTransaction"> // service元素包含一个或者多个port元素,其中每个port元素表示一个不同的Web服务。
<port binding="tns:spcSyn_spcTransaction_spcWorkflow" name="spcSyn_spcTransaction_spcWorkflow">
<soap:address location="http://172.19.100.88/aaaa/bbbb/cccc"/>
</port>
</service> </definitions>
(PHP)用cURL调用WebService获取天气信息
<?php
/**
* 用cURL调用WebService获取天气信息
* User: Ollydebug
* Date: 2015/11/11
* Time: 19:44
*/ //在WeatherWs的服务器上,默认大连城市的 theCityCode = 864 $data = 'theCityCode=864&theUserID=';
$curlobj = curl_init(); curl_setopt($curlobj,CURLOPT_URL,"http://www.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather");
curl_setopt($curlobj,CURLOPT_HEADER,0);
curl_setopt($curlobj,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlobj,CURLOPT_POST,1);
curl_setopt($curlobj,CURLOPT_POSTFIELDS,$data);
curl_setopt($curlobj,CURLOPT_HTTPHEADER,array("application/x-www-form-urlencoded;charset=utf-8;","Content-length: ".strlen($data)));
curl_setopt($curlobj, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36'); $rtn = curl_exec($curlobj);
if(!curl_errno($curlobj)){
echo $rtn;
}else{
echo 'Curl error: '.curl_errno($curlobj);
}
curl_close($curlobj); ?>
WebService SOAP WSDL UDDI 使用php的curl、PHP5的SoapClient实现同步的更多相关文章
- webservice SOAP WSDL UDDI简介
WebServices简介 先给出一个概念 SOA ,即Service Oriented Architecture ,中文一般理解为面向服务的架构, 既然说是一种架构的话,所以一般认为 SOA 是包含 ...
- [Java] webservice soap,wsdl 例子
java 调用webservice的各种方法总结 现在webservice加xml技术已经逐渐成熟,但要真正要用起来还需时日!! 由于毕业设计缘故,我看了很多关于webservice方面的知识,今天和 ...
- 学习 WebService 第一步:体系结构、三元素SOAP/WSDL/UDDI
原文地址:爱军的博客——WebService简介 一.为什么需要Web Service 笔记: WebService 可以实现 跨(硬件.服务器.开发工具.平台.应用程序.程序语言……)共享数据和应用 ...
- WebService三大基本元素 SOAP WSDL UDDI
转自:https://blog.csdn.net/hhooong/article/details/51763128 1.SOAP 即 Simple Object AccessProtocol 也就是简 ...
- 彻底理解webservice SOAP WSDL
WebServices简介 先给出一个概念 SOA ,即Service Oriented Architecture ,中文一般理解为面向服务的架构, 既然说是一种架构的话,所以一般认为 SOA 是包含 ...
- 理解WebService SOAP WSDL
WebServices简介 先给出一个概念 SOA ,即Service Oriented Architecture ,中文一般理解为面向服务的架构, 既然说是一种架构的话,所以一般认为 SOA 是包含 ...
- 【🉐】 彻底理解webservice SOAP WSDL
原文: http://wenku.baidu.com/view/f87b55f19e31433239689314.html WebServices简介 先给出一个概念 SOA ,即Service Or ...
- webservice soap wsdl简介
先给出一个概念 SOA ,即Service Oriented Architecture ,中文一般理解为面向服务的架构, 既然说是一种架构的话,所以一般认为 SOA 是包含了运行环境,编程模型, 架构 ...
- (文摘)彻底理解webservice SOAP WSDL
WebServices特点介绍 WebServices 提供一个建立分布式应用的平台,使得运行在不同操作系统和不同设备上的软件,或者是用不同的程序语言和不同厂商的软件开发工具开发的软件,所有可能的已开 ...
随机推荐
- vue 单文件组件
在很多vue项目中,我们使用vue.component来定义全局组件,紧接着用new Vue({el:'#container'})在每个页面内指定一个容器元素 这种方式在很多中小规模的项目中运作的很好 ...
- cocos2d-JS (二)Cocos Creater
我觉得我们开发使用最新的工具.这对于我们非常有帮助. 由于新的工具有着新的功能,简化了我们开发的模式. 站在巨人的肩膀上~~~~~~~~~~~~~ CocosCreator.最大的两个特点 组件化 ...
- Node.js 配置Nginx
1.修改nginx.conf upstream nodejs { server 127.0.0.1:3000; #server 127.0.0.1:3001; keepalive 64; } serv ...
- linux下安装python的第三方module
1.首先需要有python环境 2.安装pip软件:下载地址,https://pypi.python.org/pypi/pip/6.0.8 解压pip的压缩包:sudo tar -zxvf pip-6 ...
- 【黑马Android】(04)数据库的创建和sql语句增删改查/LinearLayout展示列表数据/ListView的使用和BaseAdater/内容提供者创建
数据库的创建和sql语句增删改查 1. 载入驱动. 2. 连接数据库. 3. 操作数据库. 创建表: create table person( _id integer primary key, nam ...
- JQ实现小火箭效果
点击返回顶部以动画方式返回 $(function(){ $(window).scroll(function(){ //当滚动距离超过50后,显示按钮: ...
- hdu1027(n个数的按字典序排列的第m个序列)
题目信息:给出n.m,求n个数的按字典序排列的第m个序列 http://acm.hdu.edu.cn/showproblem.php? pid=1027 AC代码: /** *全排列的个数(次序) ...
- ubuntu1204-gedit中文乱码
1 在界面上使用ALT-F2打开"执行应用程序"界面. 2 输入dconf-editor.然后点击"执行"打开"Configuration Edito ...
- ubuntu14.04安装vmware workstation
0) Do the basic system installation of Ubuntu 14.04 LTS (Server or Desktop) 1) wget the installer wg ...
- Material design之New Widgets(RecyclerView CardView)
New Widgets:提供了两个新的控件 RecyclerView CardView 这两个控件包含在了Android L的support library中, 他们可以用于显示复杂的布局而且都默认采 ...