使用 PHP 的本机 SOAP 类时生成 WSDL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/568916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating WSDL when using PHP's native SOAP class?
提问by
I'm using the native SOAP class in PHP 5, having changed from NuSOAP as the native class is faster (and NuSOAP development seems to have ceased). However the PHP 5 SOAP lacks the ability to generate WSDL.
我在 PHP 5 中使用本机 SOAP 类,因为本机类更快(而且 NuSOAP 开发似乎已经停止),所以我已经从 NuSOAP 改变了。然而,PHP 5 SOAP 缺乏生成 WSDL 的能力。
Has anyone experience of generating WSDL in PHP? If so, please recommend your preferred method.
有没有人在 PHP 中生成 WSDL 的经验?如果是这样,请推荐您的首选方法。
Thanks.
谢谢。
回答by daynier
Stuart,
斯图尔特,
If you or anyone else is looking for a solution to this problem here's what I did.
如果您或其他任何人正在寻找解决此问题的方法,这就是我所做的。
First get this script: http://www.phpclasses.org/browse/download/zip/package/3509/name/php2wsdl-2009-05-15.zip
首先得到这个脚本:http: //www.phpclasses.org/browse/download/zip/package/3509/name/php2wsdl-2009-05-15.zip
Then look at its example files. After that I just sliced it the way I needed because I'm using codeigniter:
然后查看它的示例文件。之后,我只是按照我需要的方式对其进行了切片,因为我正在使用 codeigniter:
function wsdl(){
error_reporting(0);
require_once(APPPATH."/libraries/WSDLCreator.php"); //Path to the library
$test = new WSDLCreator("Webservice", $this->site."/wsdl");
//$test->includeMethodsDocumentation(false);
$test->addFile(APPPATH."/controllers/gds.php");
$test->addURLToClass("GDS", $this->site);
$test->ignoreMethod(array("GDS"=>"GDS"));
$test->ignoreMethod(array("GDS"=>"accessCheck"));
$test->createWSDL();
$test->printWSDL(true); // print with headers
}
That it, your all done. Btw, I'm using SoapServer and SoapClient in php5+
那它,你的一切都完成了。顺便说一句,我在 php5+ 中使用 SoapServer 和 SoapClient
回答by Ciaran McNulty
Generating a WSDL on the fly is not something that happens very often - it would tend to raise a few questions about the stability of your service!
动态生成 WSDL 并不是经常发生的事情 - 它往往会引发一些关于服务稳定性的问题!
Zend Studio can generate a WSDL from a PHP class, and there are a few other similar tools.
Zend Studio 可以从 PHP 类生成 WSDL,还有一些其他类似的工具。
If you do need to generate the WSDL dynamically, take a look at Zend Framework library: Zend_Soap_AutoDiscover
如果您确实需要动态生成 WSDL,请查看 Zend 框架库:Zend_Soap_AutoDiscover
回答by Pablius
You can try these options:
- https://code.google.com/p/php-wsdl-creator/(GPLv3)
- https://github.com/piotrooo/wsdl-creator/(GPLv3)
- http://www.phpclasses.org/package/3509-PHP-Generate-WSDL-from-PHP-classes-code.html(BSD like)
您可以尝试以下选项:
- https://code.google.com/p/php-wsdl-creator/(GPLv3)
- https://github.com/piotrooo/wsdl-creator/(GPLv3)
- http:// /www.phpclasses.org/package/3509-PHP-Generate-WSDL-from-PHP-classes-code.html(类似BSD)
The first one might be your best option if the licence fits your project.
如果许可证适合您的项目,第一个可能是您的最佳选择。
回答by Osaro Gabriel
Zend_Soap_AutoDiscover is a good alternative to NuSOAP. But, you can also create the WSDL file from scratch which can be very complicated and error prone. To ease this process, you can use an IDE to generate the WSDL file for your PHP functions and pass it as a parameter to your PHP SoapServer class. Check out the complete tutorial on How to generate wsdl for php native soap class
Zend_Soap_AutoDiscover 是 NuSOAP 的一个很好的替代品。但是,您也可以从头开始创建 WSDL 文件,这可能非常复杂且容易出错。为了简化此过程,您可以使用 IDE 为 PHP 函数生成 WSDL 文件,并将其作为参数传递给 PHP SoapServer 类。查看关于如何为 php native soap 类生成 wsdl的完整教程

