您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 安康分类信息网,免费分类信息发布

使用PHP的soap扩展, 进行wdsl操作

2025/4/5 19:08:34发布22次查看
本文是一个使用php soap访问webservice的例子. wsdl文件请见http://www.webxml.com.cn/这个网站. 里面有很多好用的服务器. 大部分可以免费使用, 有一部分要收费. 以中文简繁转换为例. 简繁转换的wsdl文件地址为:http://webservice.webxml.com.cn/webservices
本文是一个使用php soap访问webservice的例子.
wsdl文件请见http://www.webxml.com.cn/ 这个网站. 里面有很多好用的服务器.
大部分可以免费使用, 有一部分要收费.
以中文简繁转换为例.
简繁转换的wsdl文件地址为: http://webservice.webxml.com.cn/webservices/traditionalsimplifiedwebservice.asmx?wsdl
下面是php代码, 其中有说明.
__getfunctions() ); // 这是此接口可以提供哪些服务, 就是函数定义, 有参数, 有返回值var_dump( $soap->__gettypes() ); // 这是此接口使用的数据类型.
以下为上面例子的返回值:
函数声明
array (size=4) 0 => string 'tosimplifiedchineseresponse tosimplifiedchinese(tosimplifiedchinese $parameters)' (length=80) 1 => string 'totraditionalchineseresponse totraditionalchinese(totraditionalchinese $parameters)' (length=83) 2 => string 'tosimplifiedchineseresponse tosimplifiedchinese(tosimplifiedchinese $parameters)' (length=80) 3 => string 'totraditionalchineseresponse totraditionalchinese(totraditionalchinese $parameters)' (length=83)

类型定义
array (size=4) 0 => string 'struct tosimplifiedchinese { string stext;}' (length=45) 1 => string 'struct tosimplifiedchineseresponse { string tosimplifiedchineseresult;}' (length=73) 2 => string 'struct totraditionalchinese { string stext;}' (length=46) 3 => string 'struct totraditionalchineseresponse { string totraditionalchineseresult;}' (length=75)
从这个输出中, 可以看到, 
totraditionalchineseresponse totraditionalchinese(totraditionalchinese $parameters)
这是简体转换为繁体的函数.
参数 totraditionalchinese 
结构为:
struct totraditionalchinese { string stext;}
对应 于php, 就是一个数组, 以stext为键, 值为字符串,
例如: array( 'stext' => '要转成繁体的汉字' )
此函数的返回值为:
struct totraditionalchineseresponse { string totraditionalchineseresult;}
这对于php就是, 一个stdclass, 有一个叫做totraditionalchineseresult的属性
下面是一个有完整返回值的php代码, 其中包含发送的xml信息和接收的xml信息.
true) );// 直接调用这个函数, 因为在此对象中, 所有的函数都是以双下划线开头, 所以不会有冲突.$rs = $soap->totraditionalchinese( array( 'stext' => '我要转成繁体哦, 龙' ));// 显示转换以后的值, stdclass对象.var_dump( $rs );// 显示转换的内容, 字符串echo $rs->totraditionalchineseresult;echo '以下为收发信息';// 发送http头var_dump( $soap->__getlastrequestheaders() );// 发送的http_bodyvar_dump( $soap->__getlastrequest() );// 接收的http头var_dump( $soap->__getlastresponseheaders() );// 接收的http_bodyvar_dump( $soap->__getlastresponse() );
以下是上面这个例子的返回值:object(stdclass)[2]
  public 'totraditionalchineseresult' => string '我要轉成繁體哦, 龍' (length=26)
我要轉成繁體哦, 龍
以下为收发信息
string 'post /webservices/traditionalsimplifiedwebservice.asmx http/1.1
host: webservice.webxml.com.cn
connection: keep-alive
user-agent: php-soap/5.3.13
content-type: text/xml; charset=utf-8
soapaction: http://webxml.com.cn/totraditionalchinese
content-length: 305
' (length=269)
string '
我要转成繁体哦, 龙
' (length=305)
string 'http/1.1 200 ok
date: thu, 17 jul 2014 08:55:43 gmt
server: microsoft-iis/6.0
x-powered-by: asp.net
x-aspnet-version: 2.0.50727
cache-control: private, max-age=0
content-type: text/xml; charset=utf-8
content-length: 420
' (length=228)
string '我要轉成繁體哦, 龍' (length=420)
安康分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录