php5下web service的大致浏览(注意php调用.net的web services的方式)
嗯,又找到一些好玩的东西,web service。有个叫Nusoap类,在php4下比较流行。但是淡水这次玩的是php5,所以他就没戏了。
先恶补一下相关知识。
先要打开php5的web service扩展。linux下,嗯,好像不会-_-!。windows下,把php.ini文件中 extension=php_soap.dll 去掉注释即可。
方法:
SoapClient->__soapCall()
说明:
class SoapClient {
mixed __soapCall ( string function_name, array arguments [, array options [, mixed input_headers [, array &output_headers]]])
}
In WSDL mode, you can simply call SOAP functions as SoapClient methods. This method useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers
返回值:
一个简单类型的返回值,或是一个关联数组
例子:
1.in WSDL mode
soapCall应用web service,例子用的是asp.net的web service,提供service.asmx页面,调用及查看都比较简单,手册上的example也大多是这个类型,比较简单.
SOAP发送的协议:
POST /servicepath/service.asmx HTTP/1.1
Host: 211.186.1.4
Content-Type: text/xml;
Content-Length: length
SOAPAction: “http://211.186.5.15/Service/ServiceMethod”
stringstringstring 调用方法:
2.in non-WSDL mode
这种情况下soapaction is unknown
SOAP发送协议:
POST /services/SoapMethod?WSDL HTTP/1.1
Host: 220.211.1.12:8088
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.2.5
Content-Type: text/xml; charset=utf-8
SOAPAction: “urn:SoapMethod#ServiceMethod”
Content-Length: 1297
0101910011 调用方法:
附注一下:
class SoapParam {
__construct ( mixed data, string name )
}
参数:
data
The data to pass or return. You can pass this parameter directly as PHP value, but in this case it will be named as paramN and the SOAP Service may not understand it.
name
参数名
页:
[1]