php wsdl生成类
来源:互联网 发布:qq点亮图标软件 编辑:程序博客网 时间:2024/06/05 16:02
[1].[代码] wsdl处理类 跳至 [1] [2] [3]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
* wsdl处理类
*/
class
SoapDiscovery {
private
$class_name
=
''
;
private
$service_name
=
''
;
/**
* SoapDiscovery::__construct() SoapDiscovery class Constructor.
*
* @param string $class_name
* @param string $service_name
**/
public
function
__construct(
$class_name
=
''
,
$service_name
=
''
) {
$this
->class_name =
$class_name
;
$this
->service_name =
$service_name
;
}
/**
* SoapDiscovery::getWSDL() Returns the WSDL of a class if the class is instantiable.
*
* @return string
**/
public
function
getWSDL() {
if
(
empty
(
$this
->service_name)) {
throw
new
Exception(
'No service name.'
);
}
$headerWSDL
=
"<?xml version=\"1.0\" ?>\n"
;
$headerWSDL
.=
"<definitions name=\"$this->service_name\" targetNamespace=\"urn:$this->service_name\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tns=\"urn:$this->service_name\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n"
;
$headerWSDL
.=
"<types xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />\n"
;
if
(
empty
(
$this
->class_name)) {
throw
new
Exception(
'No class name.'
);
}
$class
=
new
ReflectionClass(
$this
->class_name);
if
(!
$class
->isInstantiable()) {
throw
new
Exception(
'Class is not instantiable.'
);
}
$methods
=
$class
->getMethods();
$portTypeWSDL
=
'<portType name="'
.
$this
->service_name.
'Port">'
;
$bindingWSDL
=
'<binding name="'
.
$this
->service_name.
'Binding" type="tns:'
.
$this
->service_name."Port\
">\n<soap:binding style=\"rpc\" transport=\"http://schemas.xmlsoap.org/soap/http\" />\n"
;
$serviceWSDL
=
'<service name="'
.
$this
->service_name."\
">\n<documentation />\n<port name=\""
.
$this
->service_name.
'Port" binding="tns:'
.
$this
->service_name.
"Binding\"><soap:address location=\"http://"
.
$_SERVER
[
'SERVER_NAME'
].
':'
.
$_SERVER
[
'SERVER_PORT'
].
$_SERVER
[
'PHP_SELF'
].
"\" />\n</port>\n</service>\n"
;
$messageWSDL
=
''
;
foreach
(
$methods
as
$method
) {
if
(
$method
->isPublic() && !
$method
->isConstructor()) {
$portTypeWSDL
.=
'<operation name="'
.
$method
->getName()."\
">\n"
.
'<input message="tns:'
.
$method
->getName()."Request\
" />\n<output message=\"tns:"
.
$method
->getName().
"Response\" />\n</operation>\n"
;
$bindingWSDL
.=
'<operation name="'
.
$method
->getName()."\
">\n"
.
'<soap:operation soapAction="urn:'
.
$this
->service_name.
'#'
.
$this
->class_name.
'#'
.
$method
->getName()."\
" />\n<input><soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</input>\n<output>\n<soap:body use=\"encoded\" namespace=\"urn:$this->service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n</output>\n</operation>\n"
;
$messageWSDL
.=
'<message name="'
.
$method
->getName()."Request\
">\n"
;
$parameters
=
$method
->getParameters();
foreach
(
$parameters
as
$parameter
) {
$messageWSDL
.=
'<part name="'
.
$parameter
->getName()."\
" type=\"xsd:string\" />\n"
;
}
$messageWSDL
.=
"</message>\n"
;
$messageWSDL
.=
'<message name="'
.
$method
->getName()."Response\
">\n"
;
$messageWSDL
.=
'<part name="'
.
$method
->getName()."\
" type=\"xsd:string\" />\n"
;
$messageWSDL
.=
"</message>\n"
;
}
}
$portTypeWSDL
.=
"</portType>\n"
;
$bindingWSDL
.=
"</binding>\n"
;
return
sprintf(
'%s%s%s%s%s%s'
,
$headerWSDL
,
$portTypeWSDL
,
$bindingWSDL
,
$serviceWSDL
,
$messageWSDL
,
'</definitions>'
);
}
/**
* SoapDiscovery::getDiscovery() Returns discovery of WSDL.
*
* @return string
**/
public
function
getDiscovery() {
return
"<?xml version=\"1.0\" ?>\n<disco:discovery xmlns:disco=\"http://schemas.xmlsoap.org/disco/\" xmlns:scl=\"http://schemas.xmlsoap.org/disco/scl/\">\n<scl:contractRef ref=\"http://"
.
$_SERVER
[
'SERVER_NAME'
].
':'
.
$_SERVER
[
'SERVER_PORT'
].
$_SERVER
[
'PHP_SELF'
].
"?wsdl\" />\n</disco:discovery>"
;
}
}
?>
[2].[代码] wsdl服务端接收 跳至 [1] [2] [3]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
+------------------------------------------------------------------------------
* wsdl服务端
+------------------------------------------------------------------------------
* @wsdl服务端接收
+------------------------------------------------------------------------------
*/
define(
'WSDL_URL'
,
'hello.wsdl'
);
//定义WSDL文件路径
ini_set
(
'soap.wsdl_cache_enabled'
,
'0'
);
//关闭WSDL缓存
//WSDL文件不存在时自动创建
if
(!
file_exists
(WSDL_URL))
{
require_once
'SoapDiscovery.class.php'
;
//引入类
$disco
=
new
SoapDiscovery(
'Mywsdl'
,
'www.fuheishu.com'
);
$str
=
$disco
->getWSDL();
file_put_contents
(WSDL_URL,
$str
);
}
//SOAP开启并接收Client传入的参数响应
$server
=
new
SoapServer(WSDL_URL);
$server
->setClass(
'Mywsdl'
);
$server
->handle();
//测试定义公开的类
class
Mywsdl {
private
$nombre
=
''
;
public
function
__construct(
$name
=
'World'
)
{
$this
->name =
$name
;
}
public
function
greet(
$name
=
''
)
{
$name
=
$name
?
$name
:
$this
->name;
return
'Hello '
.
$name
.
'.'
;
}
public
function
serverTimestamp()
{
return
time();
}
public
function
myfunc(
$a
=
''
){
return
$a
;
}
}
?>
[3].[代码] wsdl客户端 跳至 [1] [2] [3]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
/**
+------------------------------------------------------------------------------
* wsdl客户端
+------------------------------------------------------------------------------
* @wsdl客户端发送
+------------------------------------------------------------------------------
*/
$client
=
new
SoapClient(
"http://127.0.0.1/createsoap/hello.wsdl"
);
try
{
$result
=
$client
->myfunc(
'789'
);
var_dump(
$result
);
//echo "The answer isresult";
}
catch
(SoapFault
$f
){
echo
"Error Message: {$f->getMessage()}"
;
}
?>
0 0
- php wsdl生成类
- PHP 生成 WSDL 文件工具类 SoapDiscovery.class.php
- Zend Studio for Eclipse 从PHP类生成WSDL文件
- php中soap 的使用实例无需手写WSDL文件,提供自动生成WSDL文件类
- php中soap 的使用实例无需手写WSDL文件,提供自动生成WSDL文件类
- WSDL代理类生成
- 根据wsdl生成类
- PHP 生成WSDL 以及 提供SOAP服务
- php学习之道:php中soap的使用实例以及生成WSDL文件,提供自动生成WSDL文件的类库——SoapDiscovery.class.php类
- wsdl生成代理类命令
- wsdl 生成 webservice 代理类
- wsimport生成wsdl代理类
- php中soap的使用实例以及生成WSDL文件,提供自动生成WSDL文件的类库——SoapDiscovery.class.php类
- 通过WSDL命令,将WSDL生成代理类
- php soap举例及wsdl文件的生成
- PHP Soap续:zend studio 7 生成wsdl
- php zend studio 自动生成wsdl文件详解
- php中soap 的使用实例和一些个人看法!亲测,无需手写WSDL文件,提供自动生成WSDL文件类
- Spring Internals -- 目录
- 将UIView加载成WevView(不懂的可以留言)
- 利用Cookie实现用户浏览商品记录
- URL的格式
- 8.31学习总结
- php wsdl生成类
- Linux介绍
- 利用Coding.net代码托管空间免费部署个人主页网站
- django_学习笔记0901
- UDP 广播编程研究一
- 搭建mysqlproxy的过程
- 45天的坚持是否值得——倒数43天
- Androidannotations框架快速搭建
- 新特性页面,选择控制器的启动方式(代码演示)