学了几种语言,有时回想,却发现没什么积累,偏偏自己又喜欢卖弄;怎奈何自己又不甘堕落,于是乎就强迫自己写写日记,但是自己跟自己对话又觉得没意思, 就想着把日志写成教程,给社区里的难兄难弟没做做参考.小弟实在是没有什么经验,还望那些看到本文的有缘人多多包涵....
php5自带了一个开发web service的扩展extension=php_soap.dll;
在php.ini中加入上面扩展;同时配置ini文件的以下选项
Name Default Changeable Changelog
soap.wsdl_cache_enabled "1" PHP_INI_ALL Available since PHP 5.0.0.
soap.wsdl_cache_dir "/tmp" PHP_INI_ALL Available since PHP 5.0.0.
soap.wsdl_cache_ttl "86400" PHP_INI_ALL Available since PHP 5.0.0.
这样就可以使用SoapServer了.
那建一个文件,内容如下
class service_class {
/**
* @return string
* */
function sayHello(){
return ''hello world'';
}
/**
* @param string $name;
* @return string;
*/
function getName($name){
return $name;
}
}
$server = new SoapServer(''buildin.wsdl'');(1)
$server->setClass(''service_class'');(2)
$server->handle();(3)
?>
这里有一点需要注意的是:如果要在生成的wsdl文件有类型的话,应使用方法注释;(string,integer等).
(1)生成一个实例,参数"buildin.wsdl"是wsdl文件所在的位置,因为SoapServer还没有提供生成wsdl的实现,因些要指明细wsdl文件所在的位置.
(2)注册webservice的提供的方法,默认为类里面的所有方法
(3)处理请求;
到这里为止,在浏览器中访问本php文件,如果出现如果提示
"cant find HTTP_RAW_POST_DATA";则在创建soapServer前,插入以下代码
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if (!isset($HTTP_RAW_POST_DATA)){
$HTTP_RAW_POST_DATA = file_get_contents(''php://input'');
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
此时如果提示bad request之类的错误,说明web service已经启动了.
如果没有忘记前面前到的wsdl的话,此刻必会想即然不还不能生成wsdl文件的话,那那个buildin.wsdl从何而来呢,如果对zend studio熟悉的话,就会想到tool菜单下面的wsdl generator,对了,用这个工具可以生成很帅的wsdl文件,使用方法在这里就不多说了,自己就两下就知道是怎么生成了..
server端到此结束.
令天就先到这里,,明天接续delphi客户端如果调用.....

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
