欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

WebService-php- 1(16),webservice-php-16_PHP教程

程序员文章站 2022-06-06 17:59:49
...

WebService-php- 1(16),webservice-php-16

最近看了挺多关于php中webservice的资料,感谢燕十八的分享,帮助了我构建服务端的过程。将学习笔记记录如下,其中包含燕十八的笔记。

WebService

1 快速了解WebService

通俗的说:按一定的XML格式,调用远程服务器的方法,且服务器按一定的格式返回XML内容.
"一定的格式"----SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协
议.
远程服务器 ---- 一般通过HTTP协议来传递消息
总结: WebServie == HTTP协议 + Soap格式的XML

例1:soap请求

  POST /WebServices/MobileCodeWS.asmx HTTP/1.1
  Host: webservice.webxml.com.cn
  Content-Type: text/xml; charset=utf-8
  Content-Length: 354
  SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
  
    并重启apache
  PHP SoapClient类可以用来请求WebService

$soap = new soapClient('http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL');
print_r($soap->getMobileCodeInfo( array('mobileCode'=>'13**********') ) );
Array
(
[0] => getMobileCodeInfoResponse getMobileCodeInfo(getMobileCodeInfo $parameters)
[1] => getDatabaseInfoResponse getDatabaseInfo(getDatabaseInfo $parameters)
)
Array
(
[0] => struct getMobileCodeInfo {
string mobileCode;
string userID;
}
[1] => struct getMobileCodeInfoResponse {
string getMobileCodeInfoResult;
}
[2] => struct getDatabaseInfo {
}
[3] => struct getDatabaseInfoResponse {
ArrayOfString getDatabaseInfoResult;
}
[4] => struct ArrayOfString {

string string;
}

// 调用方法
print_r($soap->getMobileCodeInfo( array('mobileCode'=>'13426060134') ) );

返回结果

stdClass Object ( [getMobileCodeInfoResult] => 13*********:北京 北京 北京移动动感地带卡 )

3 搭建WebService服务器

wsdl是什么?
wsdl是WebService的规格说明书.

'
相关标签: webservice