博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP WebService/Soap接口生成方法。
阅读量:6943 次
发布时间:2019-06-27

本文共 3494 字,大约阅读时间需要 11 分钟。

WSDL方法:

配置: php.ini->;php_soap.all 把前面的;号去掉,开启soap。

准备SoapDiscovery.class.php类(作用:生成WSDL文件)

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 = "
\n"; $headerWSDL.= "
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.= "
\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 = '
'; $bindingWSDL = '
\n
\n"; $serviceWSDL = '
\n
\n
service_name.'Port" binding="tns:'.$this->service_name."Binding\">
\n
\n
\n"; $messageWSDL = ''; foreach ($methods as $method) { if ($method->isPublic() && !$method->isConstructor()) { $portTypeWSDL.= '
\n".'
\n
getName()."Response\" />\n
\n"; $bindingWSDL.= '
\n".'
\n
service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n\n
\n
service_name\" encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" />\n
\n
\n"; $messageWSDL.= '
\n"; $parameters = $method->getParameters(); foreach ($parameters as $parameter) { $messageWSDL.= '
\n"; } $messageWSDL.= "
\n"; $messageWSDL.= '
\n"; $messageWSDL.= '
\n"; $messageWSDL.= "
\n"; } } $portTypeWSDL.= "
\n"; $bindingWSDL.= "\n"; return sprintf('%s%s%s%s%s%s', $headerWSDL, $portTypeWSDL, $bindingWSDL, $serviceWSDL, $messageWSDL, '
'); } /** * SoapDiscovery::getDiscovery() Returns discovery of WSDL. * * @return string **/ public function getDiscovery() { return "
\n
\n
\n
"; }}?>
View Code

创建service.php(与SoapDiscovery文件同一个文件夹中)

getWSDL(); file_put_contents($wsdl,$wsdlxmlstr);}//定义接口 $SoapServer = new SoapServer($wsdl);$SoapServer->setClass($class);$SoapServer->handle();

之后在浏览器上运行service.php,生成WSDL文件。

 

创建一个模拟PHP客户端Client.php

say();}catch(SoapFault $e){ echo $client->__getLastRequest(); echo $client->__getLastResponse(); echo $e->getMessage();}

Hello World!

 

线上问题:

  1.线上需要开启缓存,加速加载。

  php.ini->soap.wsdl_cache_enabled=1 

 

  2.每一次修改远程函数建议删除WSDL文件再生成一次。

 

转载于:https://www.cnblogs.com/ChivanTam/p/4846973.html

你可能感兴趣的文章
atitit.attilax的软件 架构 理念.docx
查看>>
EF实体框架之CodeFirst四
查看>>
[Tex学习]WinEdit 常用软件快捷键
查看>>
二维码在短信业务应用的初步构思
查看>>
分布式服务器集群架构方案思考
查看>>
Graphviz使用简介(中文乱码的问题)
查看>>
Log4J使用
查看>>
【反编译系列】三、反编译神器(jadx)
查看>>
Xamarin Essentials教程安全存储SecureStorage
查看>>
[Maid] Write Tasks in Markdown with Maid
查看>>
tf.reducemean()到底是什么意思?
查看>>
像调试java一样来调试Redis lua
查看>>
What is Socket.IO?
查看>>
使用select实现非阻塞socket | dbafree首页
查看>>
The bug when Use Tomat in Eclipse
查看>>
wine 源
查看>>
抽象工厂资料汇总
查看>>
javascript 杂谈之哪种写法你更喜欢?
查看>>
nil localizedTitle in SKProduct
查看>>
EGORefreshTableHeaderView学习
查看>>